Maybe a list comprehsnion is not the right way to go here.
I want to define a nested list that a user can tell how many lists and how many entries in each subllist. Then have random call a value for each entry in the sublist, working on unique entries for each sublist(but can get round to that later
So I created a basic test case
import random d = (1, 2, 3, 4, 5, 6, 7, 8, 9) userVal1 = 3 userVal2 = 4 arand = random.choice(d) x = [[arand for i in range(userVal1)] for j in range(userVal2)] print x
Now it creates a list of 3 entries 4 times so that works.
sayth@linux-g8u9:~/dev/multi> python3 test_loop.py [[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]]
But it only pulls the first random number and populates it across the list, I want it to repick for each entry.
NB I have a better random system I am working on so that function arand is just for testing in this case.
for some reason I really cannot get my head around list comprehsenions and/or looping to create multiple lists.
Edit: I have tried a list comprehension, it is not necessary that this would need to be the solution.
Edited 3 Years Ago by flebber