Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #37639 > unrolled thread
| Started by | Rob Day <robert.day@merton.oxon.org> |
|---|---|
| First post | 2013-01-24 21:41 +0000 |
| Last post | 2013-01-24 21:41 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Dict comp help Rob Day <robert.day@merton.oxon.org> - 2013-01-24 21:41 +0000
| From | Rob Day <robert.day@merton.oxon.org> |
|---|---|
| Date | 2013-01-24 21:41 +0000 |
| Subject | Re: Dict comp help |
| Message-ID | <mailman.1021.1359063688.2939.python-list@python.org> |
On 24 January 2013 21:11, Oscar Benjamin <oscar.j.benjamin@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.day@merton.oxon.org
Back to top | Article view | comp.lang.python
csiph-web