creating lists question?

Josiah Carlson jcarlson at nospam.uci.edu
Tue Mar 23 16:17:20 EST 2004


> 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.

Do you mean:

lists = []
for element in list1:
     lists.append([element])

Or using list comprehensions:

lists = [[element] for element in list1]

  - Josiah



More information about the Python-list mailing list