> [b.pop(0)] > > This has to lookup the global b, resize it, create a new list, > concatenate it with the list x (which creates a new list, not an in-place > concatenation) and return that. The amount of work is non-trivial, and I > don't think that 3us is unreasonable. > I forgot to take account for the resizing of the list b. Now it makes sense. Thanks!
> Personally, the approach I'd take is: > > a = [[1,2,3], [4,5,6]] > b = [7,8] > [x+[y] for x,y in zip(a,b)] > > > Speedwise: > > $ python -m timeit -s 'a=[[1,2,3], [4,5,6]]; b=[7,8]' '[x+[y] for x,y in > zip(a,b)]' > 100000 loops, best of 3: 2.43 usec per loop > > > If anyone can do better than that (modulo hardware differences), I'd be > surprised. > Yeah, this seems to be a nice solution. Greetings, Daniel -- http://mail.python.org/mailman/listinfo/python-list