Re: list-comprehension and map question (simple)

2005-03-30 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, runsun pan <[EMAIL PROTECTED]> wrote: . . . >Secondly, [x+y for x,y in itertools.izip(xs, ys)] did go much faster >than map(lambda x,y: x+y, xs, ys). The latter is not only the slowest >one, but

Re: list-comprehension and map question (simple)

2005-03-30 Thread runsun pan
Thx, Robert. I did some tests: >>> xs = range(1) >>> ys = range(0,2,2) >>> def m1(x, count=100): ... for c in range(count): ...y = map(float, x) ... return y >>> def L1(x, count=100): ... for c in range(count): ...y = [float(z) for z in x] ... return y >>> d

Re: list-comprehension and map question (simple)

2005-03-28 Thread Robert Kern
runsun pan wrote: I remember reading somewhere that the map, filter, reduce are much faster than list comp. It depends. map(float, some_list_of_numbers) is going to be faster than [float(x) for x in some_list_of_numbers] but map(lambda x,y: x+y, xs, ys) is going to be slower than import ite

Re: list-comprehension and map question (simple)

2005-03-28 Thread runsun pan
I remember reading somewhere that the map, filter, reduce are much faster than list comp. -- http://mail.python.org/mailman/listinfo/python-list

Re: list-comprehension and map question (simple)

2005-03-27 Thread Charles Hartman
I very much take your point. And thanks: that answers my syntax question (I think!) -- *and* tells me that I don't care. Charles Hartman On Mar 27, 2005, at 2:16 PM, [EMAIL PROTECTED] wrote: ... >>> simpler == complexities True >>> I've not the glimmer of a clue which would be faster, and don't c

Re: list-comprehension and map question (simple)

2005-03-27 Thread Brian van den Broek
Brian van den Broek said unto the world upon 2005-03-27 14:12: Charles Hartman said unto the world upon 2005-03-27 13:35: On Mar 27, 2005, at 1:18 PM, Brian van den Broek wrote: >>> def some_arbitrary_function(y): ... return ( (y * 42) - 19 ) % 12 ... >>> [some_arbitrary_function(len(x)) for x

Re: list-comprehension and map question (simple)

2005-03-27 Thread Brian van den Broek
Charles Hartman said unto the world upon 2005-03-27 13:35: On Mar 27, 2005, at 1:18 PM, Brian van den Broek wrote: >>> def some_arbitrary_function(y): ... return ( (y * 42) - 19 ) % 12 ... >>> [some_arbitrary_function(len(x)) for x in lines.split()] [5, 5, 11, 11, 5, 11, 5, 11] >>> I could be m

Re: list-comprehension and map question (simple)

2005-03-27 Thread Charles Hartman
On Mar 27, 2005, at 1:18 PM, Brian van den Broek wrote: >>> def some_arbitrary_function(y): ... return ( (y * 42) - 19 ) % 12 ... >>> [some_arbitrary_function(len(x)) for x in lines.split()] [5, 5, 11, 11, 5, 11, 5, 11] >>> I could be missing some edge cases, but it seems to me that if you hav

Re: list-comprehension and map question (simple)

2005-03-27 Thread Brian van den Broek
Charles Hartman said unto the world upon 2005-03-27 09:51: I understand this toy example: lines = "this is a group\nof lines of\nwords" def getlength(w): return len(w) s = map(getlength, [word for ln in lines.split() for word in ln.splitlines()]) (now s is [4, 2, 1, 5, 2, 5, 2, 5]) My question i

Re: list-comprehension and map question (simple)

2005-03-27 Thread Reinhold Birkenfeld
Charles Hartman wrote: > On Mar 27, 2005, at 11:50 AM, Nicolas Évrard wrote: > >>> >>> I hope the question is clear enough. I have a feeling I'm ignoring a >>> simple technique . . . >> >> lambda ! >> >> map(lambda x: timestwo(getlength(x)), ...) > > Ah, lambda! I've heard so much bad-mouthing

Re: list-comprehension and map question (simple)

2005-03-27 Thread Charles Hartman
On Mar 27, 2005, at 11:50 AM, Nicolas Évrard wrote: I hope the question is clear enough. I have a feeling I'm ignoring a simple technique . . . lambda ! map(lambda x: timestwo(getlength(x)), ...) Ah, lambda! I've heard so much bad-mouthing of lambda that I forgot to learn it . . . This is quite

Re: list-comprehension and map question (simple)

2005-03-27 Thread Nicolas Évrard
* Charles Hartman [16:51 27/03/05 CEST]: I understand this toy example: lines = "this is a group\nof lines of\nwords" def getlength(w): return len(w) s = map(getlength, [word for ln in lines.split() for word in ln.splitlines()]) (now s is [4, 2, 1, 5, 2, 5, 2, 5]) My question is whether there'

list-comprehension and map question (simple)

2005-03-27 Thread Charles Hartman
I understand this toy example: lines = "this is a group\nof lines of\nwords" def getlength(w): return len(w) s = map(getlength, [word for ln in lines.split() for word in ln.splitlines()]) (now s is [4, 2, 1, 5, 2, 5, 2, 5]) My question is whether there's any compact way to combine function cal