creating lists question?
Jere Kahanpaa
kahanpaa at gstar.astro.helsinki.fi
Sat Mar 27 04:46:38 EST 2004
Hi.
spisatus <spisatus at coqui.net> wrote:
> 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.
OK, now I understand what you are trying to do. Personally I'd store the
lists in a dictionary:
names = ['aaa','bbb','ccc']
lists = {}
for name in names:
lists[name] = []
lists['aaa'].append('foo')
print lists['aaa'][0]
print lists.items()
This has the added benefit that you can operate on all lists by iterating
over namedlists.values().
Jere
--
Lord, make my words as sweet as honey, for one day I may have to eat them
- Daryl Benson
More information about the Python-list
mailing list