Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #37639

Re: Dict comp help

References <assp.07360d00b0.753cb595af8449f689dabf8b28611e52@exch.activenetwerx.com> <CAHVvXxSVH_-3VHx1VLwSah7-Y8ZwvQ9MZB7e_ZevEUcjG7ZBEQ@mail.gmail.com>
Date 2013-01-24 21:41 +0000
Subject Re: Dict comp help
From Rob Day <robert.day@merton.oxon.org>
Newsgroups comp.lang.python
Message-ID <mailman.1021.1359063688.2939.python-list@python.org> (permalink)

Show all headers | View raw


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 comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Dict comp help Rob Day <robert.day@merton.oxon.org> - 2013-01-24 21:41 +0000

csiph-web