classification
Title: inconsistent behavior of range when used in combination with remove
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.0, Python 3.1, Python 2.6, Python 2.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: r.david.murray, zero79
Priority: normal Keywords:

Created on 2009-04-23 19:15 by zero79, last changed 2009-04-23 19:47 by zero79. This issue is now closed.

Messages (3)
msg86372 - (view) Author: Michael Gilbert (zero79) Date: 2009-04-23 19:15
using range in combination with remove is inconsistent.  for example in 
python 2.x:

>>> x = range(0,3)
>>> x.remove(1)
>>> x
[0, 2]
>>> x = range(0,3).remove(1)
>>> x
>>>

and in python 3.x:
>>> x = list(range(0,3))
>>> x.remove(1)
>>> x
[0, 2]
>>> x = list(range(0,3)).remove(1)
>>> x
>>> 

why does the second approach remove all items from the list?
msg86375 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2009-04-23 19:28
>>> [1,2,3].remove(1)
>>> repr([1,2,3].remove(1))
'None'

The remove method mutates the list, and therefore like all such mutating
methods, it returns None.
msg86376 - (view) Author: Michael Gilbert (zero79) Date: 2009-04-23 19:47
ok, i see now.  the list itself is changed in place, and the return value 
of the remove() method is always None.  since i din't assign the list to a 
variable in the first place, there is hence no way now to access that 
modified list.

thanks for your help.
History
Date User Action Args
2009-04-23 19:47:48zero79setmessages: + msg86376
2009-04-23 19:28:40r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg86375

resolution: not a bug
stage: resolved
2009-04-23 19:15:31zero79create