Issue 1675516: random.randint fails on lists (original) (raw)
for i in range(400): ... l[random.randint(0,7)] ... 'g' 'g' 'c' 'c' 'b' 'b' 'g' 'g' 'd' 'g' 'd' 'f' 'd' 'a' Traceback (most recent call last): File "", line 2, in ? IndexError: list index out of range l ['a', 'b', 'c', 'd', 'e', 'f', 'g']
have no idea what the problem is. check out the error though
Please read the doc carefully. randint(a, b) can return b:
http://docs.python.org/lib/module-random.html
Return a random integer N such that a <= N <= b.
So in your case, randint(0,7) is returning 7 and tries to access l's 8th element, which results in IndexError.
Closing as invalid.