Problem of function calls from map()

Peter Otten __peter__ at web.de
Tue Aug 22 05:09:48 EDT 2006


Dasn wrote:

> # size of 'dict.txt' is about 3.6M, 154563 lines
> f = open('dict.txt', 'r')

> lines = f.readlines()
 
> def sp0(lines):
>         """====> sp0() -- Normal 'for' loop"""
>         l = []
>         for line in lines:
>                 l.append(line.split('\t'))
>         return l

Where do you get the data from in the "real world"? If it's a file you might
get the best overall performance if you skip the readlines() call:

sp0(f)

Anyway, here's another variant you can try:

from itertools import izip, starmap, repeat

def splitlines(lines):
    return list(starmap(str.split, izip(lines, repeat("\t"))))

Peter




More information about the Python-list mailing list