creating lists question?
spisatus
spisatus at coqui.net
Tue Mar 23 17:11:26 EST 2004
Josiah,
Now I know I have a long way to go:O)
I'm not sure this is doing what I want it to do. In the example I gave I
want a new list call "aaa" another list called "bbb"... so I can append to
the new list i.e., bbb.append(). It may be that your example does this but
it appears to be (with my limited knowledge) that it's creating a list of
lists, when all I want is a new isolated list.
Thanks again!!!!
"Josiah Carlson" <jcarlson at nospam.uci.edu> wrote in message
news:c3q9mr$760$1 at news.service.uci.edu...
> > 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