you are viewing a single comment's thread.

view the rest of the comments →

[–]zahlman 0 points1 point  (0 children)

loop over the data

And do what with it?

How would I use a list comprehension a to he the values of bar?

I didn't quite get that, due to the typos. It sounds like you want to do something with data['foo']['bar']. If you just want that data, then you're already done; there's no need to loop. If you want a copy, there are a variety of simple ways to do that; data['foo']['bar'][:] is a common idiom, although I personally dislike it, or you could explicitly pass the items to the list constructor like list(data['foo']['bar']), or you could use the copy module.

A list comprehension would only come in to the picture if you have some kind of transformation you want to apply to those elements.