Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialHussein Amr
2,461 PointsDidn't get how printing the minutes of the courses works
for course in course_minutes:
print(course_minutes[course])
How does that print the values exactly?
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsLet's look at the two statements. First:
for course in course_minutes:
Says:
- treat
course_minutes
as an iterable object - take each item from the iterable and assign it to the variable
course
- then run the loop code using this new value of
course
When a dict
is used in the context of an iterable, it will respond with a list of the dictionary keys. So course
will contain the various course names.
print(course_minutes[course])
Says:
- use the
course
defined by the for loop as the key to the dictcourse_minutes
- look up the value, and print it
Hope this helps. Post back if you need more help. Good Luck!!
Idan shami
13,251 PointsIdan shami
13,251 PointsI don't understand why if the course defined as a key it means to look up the value, why it is saying that, i just cannot understand it.
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsIt is the square brackets around
course
that designates it semantically as a dict key In dict notation, an item is looked up using the formsome_dict[key]
. Otherwisecourse
is just a string object.