Paul McGuire wrote: > "Dasn" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> >> 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
And why is this better than map(lambda t: t.split('\t'), data) ? Georg -- http://mail.python.org/mailman/listinfo/python-list