creating lists question?

Josef Meile jmeile at hotmail.com
Thu Mar 25 10:10:21 CET 2004


spisatus wrote:
> I'm trying to create a series of list from a loop is this possible? Let me
> give you an example:
> 
> list1 = ["aaa", "bbb", "ccc", "ddd", "eee"]
> 
> for element in list1:
>   a = element
>   a = []
> 
> 
> I want a new list created for every element in list1, how can I do this.
> 
> Thanks!!
> Spisatus
> 
> 
> 
What's about a dictionary? It would do the trick as well:

listIds=["aaa", "bbb", "ccc", "ddd", "eee"]
lists={}
for element in listIds:
   lists[element]=[]

test=lists['aaa']
test.append('foo')
print lists

Regards,
Josef



More information about the Python-list mailing list