(no subject)

Peter Otten __peter__ at web.de
Fri Sep 19 17:43:55 CEST 2003

Leeds, Mark wrote:

> python : i am a python novice and i
> am reading in a text file of say 500
> lines with the fields in each line elimited by a "|" and
> there are 90 records in each line.

Have a look at the new csv module for similar tasks.

> so, my question is , is it possible
> to take the one big list that
> i have now and tell python
> to take the fields in the list
> and make a list of lists where
> each sub list is composed of every 90
> items in the list ? I imagine this

flat = range(11) #your big list

delta = 2 # that would be 90
lol = [flat[start:start+delta] for start in range(0, len(flat), delta)]

print lol

(No special tricks here as it is throw-away code.)

> p.s : i was going to include part

*Always* a good idea to include the code that messed it up; do it next time!
The same goes for a descriptive subject line.


More information about the Python-list mailing list