Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81980
| 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 | <telnetgmike@gmail.com> |
| 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" <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 <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.16610.1417762972.18130.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
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)
#addrnum_dict = OrderedDict(sorted(addrnum_dict.items(), key=lambda t: t[0]))
if __name__ == '__main__':
kinds = ["a","b"]
for tmp_kind in kinds:
orderaddrtimes()
######################
errors:
python aaa.py
<type 'dict'>
<type 'list'>
Traceback (most recent call last):
File "aaa.py", line 16, in <module>
orderaddrtimes()
File "aaa.py", line 11, in orderaddrtimes
addrnum_dict = sorted(addrnum_dict.iteritems(), key=lambda d:d[1], reverse = True)
AttributeError: 'list' object has no attribute 'iteritems'
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
dict turn to list unexpected at runtime??? "telnetgmike@gmail.com" <telnetgmike@gmail.com> - 2014-12-05 15:01 +0800 Re: dict turn to list unexpected at runtime??? Dan Sommers <dan@tombstonezero.net> - 2014-12-05 07:15 +0000
csiph-web