Re: Problem of function calls from map()
- From: "Paul McGuire" <ptmcg@xxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 21 Aug 2006 15:55:23 GMT
"Dasn" <dasn@xxxxxxxxxxxxxx> wrote in message
news:mailman.9606.1156169593.27775.python-list@xxxxxxxxxxxxx
Hi, there.
'lines' is a large list of strings each of which is seperated by '\t'
lines = ['bla\tbla\tblah', 'bh\tb\tb', ... ]
I wanna split each string into a list. For speed, using map() instead
of 'for' loop.
Try this. Not sure how it stacks up for speed, though. (As others have
suggested, if 'for' loop is giving you speed heartburn, use a list
comprehension.)
In this case, splitUsing is called only once, to create the embedded
function tmp. tmp is the function that split will call once per list item,
using whatever characters were specified in the call to splitUsing.
-- Paul
data = [
"sldjflsdfj\tlsjdlj\tlkjsdlkfj",
"lsdjflsjd\tlsjdlfdj\tlskjdflkj",
"lskdjfl\tlskdjflj\tlskdlfkjsd",
]
def splitUsing(chars):
def tmp(s):
return s.split(chars)
return tmp
for d in map(splitUsing('\t'), data):
print d
.
- Follow-Ups:
- Re: Problem of function calls from map()
- From: Georg Brandl
- Re: Problem of function calls from map()
- From: Paul McGuire
- Re: Problem of function calls from map()
- References:
- Problem of function calls from map()
- From: Dasn
- Problem of function calls from map()
- Prev by Date: Re: How to decode a string
- Next by Date: Re: text editor suggestion?
- Previous by thread: Re: Problem of function calls from map()
- Next by thread: Re: Problem of function calls from map()
- Index(es):
Relevant Pages
|