Iterating Over Dictionaries. How to print all the elements of movies?


Replace this line with your code. Do not remove the backticks that are above or below this line.
movies = {
	"Monty Python and the Holy Grail": "Great",
	"Monty Python's Life of Brian": "Good",
	"Monty Python's Meaning of Life": "Okay"
print filter(lambda x: movies.items(), movies)


you want to print both the key, and the value (rating), items does this for you, all you need to do is print movies.items()

Iterating Over Dictionaries. How to print the values of the movies?

Ah i got it! Thank you.


A note on filter/map: list comprehension is usually preferred over filter/map, especially if you would need a lambda expression for filter/map.

When the function already exists then it's bit of a coin toss:

map(int, '1234')
[int(n) for n in '12341]
map(lambda n: int(n), '1234') # not very nice

lambda map and filter are kind of just tacked on to the language, they don't really fit in


A post was split to a new topic: Iterating over dictonary's