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


#1


https://www.codecademy.com/courses/python-beginner-en-KAgt5/4/1?curriculum_id=4f89dab3d788890003000096


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)


#2

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?
#3

Ah i got it! Thank you.


#4

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


#5

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


#6