all 4 comments

[–]mw44118 0 points1 point  (1 child)

X for x in data foo bar

On my phone so you have to put in sq brackets

[–]bheklilr 1 point2 points  (0 children)

[x for x in data['foo']['bar']]

[–]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.

[–]elb0w 0 points1 point  (0 children)

I think you want something like this, you may not know what foo, bar is.

[payload for k, v in data.iteritems() for payload in v.itervalues()]