python - "List index out of range" for list of lists -
this code:
import random fixed_set = random.sample(range(1, 11), 6) test = [[random.sample(range(1, 11), 6)] x in range(5)] x in range(5): j in range(6): print (test[x][j])
in line 7 "print (test[x][j])" error "indexerror: list index out of range" , don't understand why happening , how fix it. appreciated.
random.sample(range(1, 11), 6)
returns list , no need use []
around that.
try this:
import random test = [random.sample(range(1, 11), 6) x in range(5)] x in range(5): j in range(6): print (test[x][j])
Comments
Post a Comment