On Mon, Nov 29, 2010 at 9:53 AM, Lorin Rivers <[email protected]> wrote:
> I need to change the JSON output I get from this:
> [{"FreezeTime": "2010-11-08 21:00", "Irrad_avg": 605.00}, {"FreezeTime": 
> "2010-11-08 21:01", "Irrad_avg": 600.66}]
>
> to something more like this:
>
> [['2010-11-08 21:00',605.00], ['2010-11-08 21:01',600.66]]

Suppose all your data is in a list called ``yourdata``, and yorudata
is a list of dicts:

return [[d.get('FreezeTime'), d.get('Irrad_avg')] for d in yourdata]

You can use either the get method as I did, or the subscript notation:

return [[d['FreezeTime'], d['Irrad_avg']] for d in yourdata]

Difference is that get will assign ``None`` if a key doesn't exist,
while subscript notation will raise an exception. It depends on how
certain you can be about existence of the keys.

You can read more about list comprehensions here:

http://docs.python.org/tutorial/datastructures.html#list-comprehensions


-- 
Branko Vukelić

[email protected]
[email protected]

Check out my blog: http://www.brankovukelic.com/
Check out my portfolio: http://www.flickr.com/photos/foxbunny/
Registered Linux user #438078 (http://counter.li.org/)
I hang out on identi.ca: http://identi.ca/foxbunny

Gimp Brushmakers Guild
http://bit.ly/gbg-group

Reply via email to