[Tutor] slicing nested lists/dicts/tuples
Reed L. O'Brien
reed at intersiege.com
Tue Jun 28 22:52:57 CEST 2005
Luis N wrote:
> Hi,
>
> >>> l
> [{'last': 'Bar', 'first': 'Foo'}, {'last': 'Bar', 'first': 'Foo'},
> {'last': 'Bar', 'first': 'Foo'}, {'last': 'Bar', 'first': 'Foo'}]
>
>
> This is how I imagine it:
>
> for i in l:
> for j in l[i]:
> for k in l[i][j]:
> print k.get('first')
> print k.get('last')
>
> Is there a short and sweet way of doing this (that actually works).
>
> Luis.
strings back:
for i in l:
x = l[0].values()
x.reverse()
print " ".join(x)
Foo Bar
Foo Bar
Foo Bar
Foo Bar
lists back:
for i in l:
x = l[0].values()
x.reverse()
print x
['Foo', 'Bar']
['Foo', 'Bar']
['Foo', 'Bar']
['Foo', 'Bar']
~r
--
4.6692916090
'cmVlZG9icmllbkBnbWFpbC5jb20=\n'.decode('base64')
http://www.spreadfirefox.com/?q=affiliates&id=16474&t=1
More information about the Tutor
mailing list