[Tutor] lists

Ian! imcmeans@shaw.ca
Mon, 25 Mar 2002 23:34:42 -0800


Hello! I'd just like to say that I've been happily using python on XP for a
few months now. (to answer Rob's question). I haven't run into any glitches.

Okay, here's a question. How should I access the elements of a list in a for
loop? Right now, when I try to do it, I get a list that contains all of the
letters of each element in the list. Here's what I mean:

>>> somewords = ['goo', 'foo', 'loo', 'moo', 'too']
>>> fillme = []
>>> for word in somewords:
         fillme += word
>>> fillme
['g', 'o', 'o', 'f', 'o', 'o', 'l', 'o', 'o', 'm', 'o', 'o', 't', 'o', 'o']

How can I make the for loop work with whole strings at a time, instead of
characters?