Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.052 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; 'cpython': 0.05; 'subject:help': 0.07; 'python': 0.09; 'benjamin': 0.16; "{'a':": 0.16; 'wrote:': 0.17; 'sender:addr:gmail.com': 0.18; 'versions': 0.20; 'to:name:python-list@python.org': 0.20; 'received:209.85.216.46': 0.21; 'seems': 0.23; 'header:In-Reply- To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; "doesn't": 0.28; '>>>>': 0.29; "skip:' 10": 0.30; 'url:python': 0.32; 'to:addr :python-list': 0.33; 'received:google.com': 0.34; 'robert': 0.35; 'received:209.85': 0.35; 'url:org': 0.36; 'url:library': 0.36; 'received:209': 0.37; 'received:209.85.216': 0.37; 'subject:: ': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'different': 0.63; 'day': 0.73; '2013': 0.84; 'oscar': 0.84; 'url:items': 0.84; 'subject:comp': 0.96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type; bh=4SxGnqE7ZJkEU2fqlvVCyyb3gkRN8PwloN293/++axw=; b=gBSj2uDb7/CmSc71E8FjdSSPM2rhtjMLugwmed16tT0GWczmBxCWVsyZ+2HxTRUSka ejvUH2BSOCOqSsIw6UQrlr+Atobbb3ytFNud01lDL0tUyfl6tlfyZ5MFyfUg1JWf5u6a y7YWBy8Mse0YWhPesnd/5CH1WhSv0yVBO0gj/fp4VKBgUoVpjQhanldDXP0kkmTvbxCM 7neYw5q3Vs5Eqbxy5/Z8gnhbDSGLWgH8tXPbzGtIBB6Hyx/lf/o4RZEBaafYGRN78W3D FH+VoV1CTq9ubWEWDxLjn2gfn+lUuZZ05Y2gmtqi6PGqFYvgoxnxcvS5tF1w3XDDF755 UdvA== MIME-Version: 1.0 X-Received: by 10.49.34.146 with SMTP id z18mr4309538qei.29.1359063679809; Thu, 24 Jan 2013 13:41:19 -0800 (PST) Sender: robertkday@gmail.com In-Reply-To: References: Date: Thu, 24 Jan 2013 21:41:19 +0000 X-Google-Sender-Auth: plIsMKLCf7jA49eZqNMeyToHDHY Subject: Re: Dict comp help From: Rob Day To: "python-list@python.org" Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 14 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1359063688 news.xs4all.nl 6889 [2001:888:2000:d::a6]:38110 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:37639 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/stdtypes.html#dict.items. -- Robert K. Day robert.day@merton.oxon.org