-1

I want many (hundreds) of lists in python that follow this form:

[random.randint(1,100), random.randint(50, 100), random.randint(10,20), random.randint(1,100)]

And I want to name them list1, list2, list3, etc. all the way up to list500, list501, etc.

Is there a way to automate that all? Or should I not be using lists?

japem
  • 1,037
  • 5
  • 16
  • 30

2 Answers2

1

try this:

 my_lists = [[random.randint(1,100), random.randint(50, 100), random.randint(10,20), random.randint(1,100)] for x in range(500)]

demo for 5:

>>> my_lists [[random.randint(1,100), random.randint(50, 100), random.randint(10,20), random.randint(1,100)] for x in range(5)]
>>> my_lists
[[98, 58, 15, 63], [69, 59, 12, 37], [62, 58, 16, 7], [55, 97, 17, 55], [98, 53, 14, 90]]
Hackaholic
  • 19,069
  • 5
  • 54
  • 72
0

Here's a simple snippet that will created 'named' lists inside a dict:

rand_lists = dict(('list{}'.format(i), [random.randint(1,100), random.randint(50, 100), random.randint(10,20), random.randint(1,100)]) for i in xrange(1,501))
rand_lists['list437']
>>> [3,52,12,90]
aruisdante
  • 8,875
  • 2
  • 30
  • 37