Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Dict comp help

Reply
Thread Tools

Re: Dict comp help

 
 
Rob Day
Guest
Posts: n/a
 
      01-24-2013
On 24 January 2013 21:11, Oscar Benjamin <> 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/std...tml#dict.items.

--
Robert K. Day

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
comp.lang.python, comp.sys.ibm.pc.games.rpg, comp.arch.embedded, comp.programming, comp.text.txt vilebuzz@hotmail.com Python 1 10-23-2006 02:47 AM
comp.os.ms-windows.networking.misc,misc.invest.mutual-funds,comp.lang.python,comp.os.magic-cap,comp.sources.games.bugs . Python 0 06-19-2004 08:23 AM
misc.survivalism,comp.text.xml,comp.org.usenix.roomshare,comp.graphics.animation,comp.os.linux.development.system . XML 0 06-19-2004 08:15 AM
comp.lang.c++,comp.dcom.fax,comp.mail.misc,comp.org.usenix,comp.sys.amiga.networking . C++ 0 06-19-2004 07:54 AM
comp.sys.mac.games.misc,comp.sys.ibm.pc.hardware.misc,comp.mail.pegasus-mail.ms-windows,comp.databases.paradox,comp.dcom.sys.cisco . Cisco 0 06-19-2004 07:48 AM



Advertisments