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

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -