0

How would I go about creating a list that will store info inside the for loop. Because they keep taking in new info every loop I need a way for it to automatically create new name for the list. I hope the code clears up what I want to accomplish

x = 1
while x <= ItemsInList:
    str(x)+'list' = []
    x +=1

Is it possible to create lists like 1list = [], next loop it will be 2list = [] etc.

ayhan
  • 70,170
  • 20
  • 182
  • 203
Jan
  • 91
  • 1
  • 1
  • 8
  • Briefly: you are already familiar with the `list` type. Just use a `list` to hold the others. – TigerhawkT3 Jul 28 '16 at 12:05
  • Oh, and names like `1list` and `2list` are not valid identifiers because they begin with numbers. – TigerhawkT3 Jul 28 '16 at 12:05
  • If you _need_ the names, use a `dict` to store your `list` names as keys and the lists themselves as values. If not, a list of lists as [TigerhawkT3](http://stackoverflow.com/users/2617068/tigerhawkt3) suggested will do just fine – AdrienW Jul 28 '16 at 12:07
  • @TigerhawkT3 What do you mean under "use list to hold the others"? and would list1 and list 2 work better? – Jan Jul 28 '16 at 12:07
  • You know how you can put things into a `list`? One of the things you can put into a `list` is... another `list`. – TigerhawkT3 Jul 28 '16 at 12:08
  • @TigerhawkT3 alright that makses sence :D thank you! – Jan Jul 28 '16 at 12:09

0 Answers0