[Tutor] Python Newbie: Lost in Loop

Alan Gauld alan.gauld at btinternet.com
Fri Apr 4 20:27:43 CEST 2008


"Kent Johnson" <kent37 at tds.net> wrote

> Aside to the list:
> Did anyone else know that you can assign to a list element 
> as the target of a for statement?

Nope, and in fact I was just trying it out at the >>> prompt 
when your message came in!

On a general point for the OP, I doubt if you need the 
csv module for this. You could generate the required data 
list using a simple string split() and a single list 
comprehension:

fis = [line.split() for line in infile]

Which might simplify things slightly.

Also it might help processing to sort the list based 
on the range value. But it depends on what other 
extractions/processing need to be done.

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld





More information about the Tutor mailing list