use a loop to create lists
Thomas Goebel
Thomas.Goebel at ohm-hochschule.de
Wed Apr 10 09:55:54 EDT 2013
* On 10/04/2013 10:40, martaamunar at gmail.com wrote:
> Hi!
>
> I would like to create a list containing lists. I need each list to
> have a differente name and i would like to use a loop to name the
> list.
> [...]
> global_list=[]
> for i in range (20):
> ("list_"+i)=[] #These would be the name of the list...
> global_list.append("list_"+i)
You can use a dictionary instead of a list of lists:
global_list = {'_'.join(['list', str(i)]):[] for i in range(20)}
global_list_1 = global_list['list_0']
More information about the Python-list
mailing list