Scanning a file character by character

rzed rzantow at gmail.com
Sun Feb 22 10:21:19 EST 2009


Spacebar265 <spacebar265 at gmail.com> wrote in
news:c86cd530-cee5-4de6-8e19-304c664c9ca0 at c12g2000yqj.googlegroups.c
om: 

> On Feb 11, 1:06 am, Duncan Booth <duncan.bo... at invalid.invalid>
> wrote: 
[...]
>> >>> re.split("(\w+)", "The quick brown fox jumps, and falls
>> >>> over.")[1::2] 
>>
>> ['The', 'quick', 'brown', 'fox', 'jumps', 'and', 'falls',
>> 'over'] 
> 
> Using this code how would it load each word into a temporary
> variable. 

>>> import re
>>> list_name = re.split("(\w+)", "The quick brown fox jumps, and 
falls over.")[1::2]
>>> list_name[2]
'brown'

You see, temporary variables are set. Their names are spelled 
'list_name[x]', where x is an index into the list. If your plan was 
instead to have predefined names of variables, what would they be 
called? How many would you have? With list variables, you will have 
enough, and you will know their names.

-- 
rzed



More information about the Python-list mailing list