-2

I want to write a function that creates multiple empty lists, based on the given parameter like that:

for i in range(parameter):
    list_i = []

Then I want to loop through another given list and if I encounter the number 2 for example I want it to be added to list_2. Currently I'm trying this here:

if i in cluster_i:
   cluster_i.append(...)

But that doesn't seem to work as it should. Does anyone have a solution for that problem?

Kään
  • 1

1 Answers1

0

This is not recommended. Instead, use a dict as following:

lists = {}
for i in range(parameter):
    lists.setdefault(i, [])