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!
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 trial

Conrad Landicho
3,312 PointsDictionary comprehension
Just wondering, could it be possible to use comprehension in this example? If so, what would be the correct way to do it? Thanks for any info you can provide.
5 Answers

james south
Front End Web Development Techdegree Graduate 33,271 Pointsi was writing my answer when you posted the video link so i hadn't seen it. dict comps are used to create dicts, so i don't think they would be useful here since he's already got a dict.

Conrad Landicho
3,312 PointsHmmm.... I thought I made that comment/question on the specific video. I wonder where it went .... hang on a sec, while I search for it.

Conrad Landicho
3,312 Pointsok, found it ... .here's that video, please take a look at 2:30:
https://teamtreehouse.com/library/using-databases-in-python/meet-peewee/queries-are-your-friend

james south
Front End Web Development Techdegree Graduate 33,271 Pointsdictionary comprehensions are similar to list and set comprehensions. inside curly braces {} you put k:v for .... k in some other collection or perhaps for k,v in another dictionary. so for example:
newDict = {k:v for k, v in oldDict.items() if v < 5}
newDict = {x:x**2 for x in range(8)}

Conrad Landicho
3,312 Pointsso, I guess, the answer to my question is no ?
Christopher Shaw
Python Web Development Techdegree Graduate 58,236 PointsChristopher Shaw
Python Web Development Techdegree Graduate 58,236 PointsGood day. Please be specific in exacly what you are refering to.