Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!bcyclone05.am1.xlned.com!bcyclone05.am1.xlned.com!news.astraweb.com!border2.a.newsrouter.astraweb.com!news.tele.dk!news.tele.dk!small.news.tele.dk!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.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'true)': 0.09; 'def': 0.12; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'thanks,': 0.17; 'print': 0.22; 'header:User-Agent:1': 0.23; 'appreciated': 0.26; 'header:X-Complaints-To:1': 0.27; 'statement': 0.30; 'subject:list': 0.30; 'gives': 0.31; 'code': 0.31; 'writes:': 0.31; 'run': 0.32; 'skip:s 30': 0.35; 'charset :us-ascii': 0.36; "i'll": 0.36; 'list.': 0.37; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'received:217': 0.63; 'email addr:gmail.com': 0.63; 'reverse': 0.68; 'subject:!!!': 0.74 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: dieter Subject: Re: dict turn to list at runtime unexpected!!! Date: Fri, 05 Dec 2014 08:42:53 +0100 References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Gmane-NNTP-Posting-Host: pd9e0b085.dip0.t-ipconnect.de User-Agent: Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux) Cancel-Lock: sha1:6fWWSt/KUikLWM8qgdPCGH5vBjU= 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: 12 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1417765507 news.xs4all.nl 2857 [2001:888:2000:d::a6]:45655 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 2907 X-Received-Body-CRC: 1070332708 Xref: csiph.com comp.lang.python:81987 telnetgmike@gmail.com writes: > Why the following code gives me errors??? And why the print statement run 2 times? I'll be appreciated your helps, thanks, > addrnum_dict = {'a':1,'b':2} > def orderaddrtimes(): > global addrnum_dict > print type(addrnum_dict) > > addrnum_dict = sorted(addrnum_dict.iteritems(), key=lambda d:d[1], reverse = True) "sorted" returns a list.