Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '16,': 0.03; 'attribute': 0.07; '__name__': 0.09; 'true)': 0.09; 'python': 0.11; 'def': 0.12; "'__main__':": 0.16; 'errors:': 0.16; 'subject:???': 0.16; 'skip:# 20': 0.16; 'thanks,': 0.17; 'print': 0.22; 'received:192.168.100': 0.24; 'appreciated': 0.26; 'statement': 0.30; 'subject:list': 0.30; 'gives': 0.31; 'code': 0.31; 'file': 0.32; 'run': 0.32; '(most': 0.33; 'skip:# 10': 0.33; 'skip:s 30': 0.35; 'received:google.com': 0.35; 'charset:us-ascii': 0.36; "i'll": 0.36; 'message-id:@gmail.com': 0.38; 'to:addr:python- list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'header :Message-Id:1': 0.63; 'reverse': 0.68 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-type:content-transfer-encoding:subject:message-id:date :to:mime-version; bh=JOY1W0UW+DBqknw98oYydQ+hjahmpHnSagemcSP5peM=; b=bkn52yULf4T07uycSHMMpXYFDl5gXT5pZV2uExYHBmjSSrjABJHp0O54zW1c5YsyJG 2fx/bXkAhUB473ozVsjIuFJgfG+2HomCbrWQEMJH5Nyou7LHuKVNZ0QOPzDBgv8jlAzz hjELzo3+fxscF/6eXIqftyuyyLr9jH7VX6zh+zDnWryjH80YbXigGOiaUxXTbD4NSqxR tH2jSAjwjNywTzoovU4+eiiq0hjfD4gCPJ8isvkXfE/+BGrxoxHEXWV4aVPKTr+3MamB 95xQf1PdJ2E8IrGPkuDgHwPufu+Be5BMFDNc/E6fsHYegYcAWy3rZ81oUa/nID8Dlg6K Yj3Q== X-Received: by 10.202.86.129 with SMTP id k123mr9088662oib.58.1417762970254; Thu, 04 Dec 2014 23:02:50 -0800 (PST) From: "telnetgmike@gmail.com" Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Subject: dict turn to list unexpected at runtime??? Date: Fri, 5 Dec 2014 15:01:51 +0800 To: python-list@python.org Mime-Version: 1.0 (Mac OS X Mail 8.1 \(1993\)) X-Mailer: Apple Mail (2.1993) 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1417762972 news.xs4all.nl 2919 [2001:888:2000:d::a6]:54001 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81980 Why the following code gives me errors??? And why the print statement = run 2 times? I'll be appreciated your helps, thanks, addrnum_dict =3D {'a':1,'b':2} def orderaddrtimes(): global addrnum_dict print type(addrnum_dict) addrnum_dict =3D sorted(addrnum_dict.iteritems(), key=3Dlambda = d:d[1], reverse =3D True) #addrnum_dict =3D OrderedDict(sorted(addrnum_dict.items(), = key=3Dlambda t: t[0])) if __name__ =3D=3D '__main__': kinds =3D ["a","b"] for tmp_kind in kinds: orderaddrtimes() ###################### errors: python aaa.py=20 Traceback (most recent call last): File "aaa.py", line 16, in orderaddrtimes() File "aaa.py", line 11, in orderaddrtimes addrnum_dict =3D sorted(addrnum_dict.iteritems(), key=3Dlambda = d:d[1], reverse =3D True) AttributeError: 'list' object has no attribute 'iteritems'=