[Tutor] user-given variable names for objects

Alan Gauld alan.gauld at btinternet.com
Thu Dec 13 19:36:49 CET 2007


"Che M" <pine508 at hotmail.com> wrote

>  Although I was not familiar with what you can do with a list such 
> as you did here:
> [a for a in eventData.keys() if eventData[a] < time.time()]

This is known as a list comprehension (and is described in the 
Functional
Programming topic of my tutorial - obligatory plug :-)

> I guess .keys() is a built-in method for dictionaries to return a
> list of all their values, then?

To be accurate it returns a list of the keys, the values are the 
things you get when you access the dictionary using a key:

value = dictionary[key]

So you can do things like

for key in dictionary.keys():
    print dictionary[key]

> By the way, what was the purpose of the line with
> time.sleep(1)

It pauses for 1 second. But i'm not sure why he wanted a pause! :-)

Alan G. 




More information about the Tutor mailing list