classification
Title: Error in random.shuffle
Type: crash Stage:
Components: Library (Lib) Versions: Python 3.0
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Viscaynot, georg.brandl
Priority: normal Keywords:

Created on 2007-09-05 02:20 by Viscaynot, last changed 2007-09-05 06:20 by georg.brandl. This issue is now closed.

Messages (2)
msg55653 - (view) Author: Vizcaynot (Viscaynot) Date: 2007-09-05 02:20
In python 3.0a1 under Win XP SP2:
Typing next code:

import random
s=range(10)
random.shuffle(s)

I have next error:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\python30\lib\random.py", line 262, in shuffle
    x[i], x[j] = x[j], x[i]
TypeError: 'range' object does not support item assignment

It does not happen in python 2.5
msg55657 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-09-05 06:20
Vizcaynot schrieb:
> New submission from Vizcaynot:
> 
> In python 3.0a1 under Win XP SP2:
> Typing next code:
> 
> import random
> s=range(10)

range() now returns an iterator, not a sequence, so random.shuffle() can't
work on it. Use list(range()) if you want a list.

Georg
History
Date User Action Args
2007-09-05 06:20:19georg.brandlsetstatus: open -> closed
nosy: + georg.brandl
messages: + msg55657
resolution: not a bug
2007-09-05 02:20:43Viscaynotcreate