file data to list

Sion Arrowsmith siona at chiark.greenend.org.uk
Fri Aug 29 09:14:03 EDT 2008


Emile van Sebille  <emile at fenx.com> wrote:
>data = zip(*[xx.split() for xx in open('data.txt').read().split("\n")])

Files are iterable:

data = zip(*[xx.rstrip().split() for xx in open('data.txt')])

saves you creating the extra intermediate list resulting from split("\n").

-- 
\S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
   "Frankly I have no feelings towards penguins one way or the other"
        -- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump



More information about the Python-list mailing list