Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81979
| X-Received | by 10.236.207.136 with SMTP id n8mr14862426yho.5.1417762598944; Thu, 04 Dec 2014 22:56:38 -0800 (PST) |
|---|---|
| X-Received | by 10.50.36.71 with SMTP id o7mr19242igj.0.1417762598852; Thu, 04 Dec 2014 22:56:38 -0800 (PST) |
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!enother.net!enother.net!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!w8no4722430qac.0!news-out.google.com!jh1ni6649igb.0!nntp.google.com!h15no13575304igd.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.python |
| Date | Thu, 4 Dec 2014 22:56:38 -0800 (PST) |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=180.171.128.29; posting-account=KiucNgoAAACbELwnz4xIvg-ytCx3Q5Qg |
| NNTP-Posting-Host | 180.171.128.29 |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <e5012cb1-1820-4380-8e84-e8620481cc42@googlegroups.com> (permalink) |
| Subject | dict turn to list at runtime unexpected!!! |
| From | telnetgmike@gmail.com |
| Injection-Date | Fri, 05 Dec 2014 06:56:38 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-Received-Bytes | 1850 |
| X-Received-Body-CRC | 1399659031 |
| Xref | csiph.com comp.lang.python:81979 |
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 at runtime unexpected!!! telnetgmike@gmail.com - 2014-12-04 22:56 -0800 Re: dict turn to list at runtime unexpected!!! telnetgmike@gmail.com - 2014-12-04 23:37 -0800 Re: dict turn to list at runtime unexpected!!! dieter <dieter@handshake.de> - 2014-12-05 08:42 +0100 Re: dict turn to list at runtime unexpected!!! Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-12-05 12:43 -0500
csiph-web