This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: reverse on an empty list returns None
Type: behavior Stage: resolved
Components: Versions: Python 3.1
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ezio.melotti, tormen
Priority: low Keywords:

Created on 2010-02-08 19:03 by tormen, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg99059 - (view) Author: (tormen) Date: 2010-02-08 19:03
# python 3.1.1:

myList = []
for item in myList:
    print( item ) # <<< works

for item in myList.reverse(): # <<< breaks with: TypeError: 'NoneType' object is not iterable
    print( item ) #

# But the reverse of an empty list should really be an empty list
# ... or do I miss something here?
msg99061 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010-02-08 19:06
list.reverse() reverses the list *in place* and returns None, and "for item in None: ..." correctly raises a TypeError because None is not iterable.

You either want 
for item in reversed(mylist): ...
or
mylist.reverse()
for item in mylist: ...
msg99082 - (view) Author: (tormen) Date: 2010-02-09 01:31
Thanks for your nice feedback even though my bug report was so stupid!
History
Date User Action Args
2022-04-11 14:56:57adminsetgithub: 52134
2010-02-09 01:31:53tormensetmessages: + msg99082
2010-02-08 19:06:54ezio.melottisetstatus: open -> closed
priority: low


nosy: + ezio.melotti
messages: + msg99061
resolution: not a bug
stage: resolved
2010-02-08 19:03:41tormencreate