Re: Problem of function calls from map()



"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


.



Relevant Pages

  • Re: Problem of function calls from map()
    ... 'lines' is a large list of strings each of which is seperated by '\t' ... I wanna split each string into a list. ... function tmp. ... def splitUsing: ...
    (comp.lang.python)
  • Re: Problems with sprintf, need help on this one
    ... >I need to produce 1 character array from 3 others. ... I tried sprintf and it ... >terminates on the first 0, null, 0x00 it sees in tmp data. ... If tmp points to a concatenated list of NUL-terminate strings, ...
    (comp.lang.c)
  • Re: Problem of function calls from map()
    ... 'lines' is a large list of strings each of which is seperated by '\t' ... I wanna split each string into a list. ... To avoid function call overhead, I am not willing to use lambda function ...
    (comp.lang.python)
  • Re: Problems with sprintf, need help on this one
    ... >>I need to produce 1 character array from 3 others. ... I tried sprintf and it ... >>terminates on the first 0, null, 0x00 it sees in tmp data. ... > have some way of telling the computer how many strings are in the list. ...
    (comp.lang.c)
  • Problem of function calls from map()
    ... 'lines' is a large list of strings each of which is seperated by '\t' ... I wanna split each string into a list. ... For speed, using map() instead ... To avoid function call overhead, I am not willing to use lambda function ...
    (comp.lang.python)