On 24 January 2013 21:11, Oscar Benjamin <oscar.j.benja...@gmail.com> wrote:
>>>> l = [{'a': 'xx', 'b': 'yy', 'c': 'zz'}, {'a': 'dd', 'b': 'ee', 'c': 'ff'}]
>>>> dict(d.values()[:2] for d in l)
> {'xx': 'zz', 'dd': 'ff'}

Python doesn't guarantee any ordering of items in a dictionary; {'a':
'xx', 'b': 'yy', 'c': 'zz'}.values()[:2] may not return ['xx', 'zz']
in different Python implementations or future versions (though it
seems to work consistently in CPython 2.7). See
http://docs.python.org/2/library/stdtypes.html#dict.items.

--
Robert K. Day
robert....@merton.oxon.org
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to