> [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 acc
Many thanks for all these suggestions! here is a short proof that you
guys are absolutely right and my solution is pretty inefficient.
One of your ways:
$ python /[long_path]/timeit.py 'a=[(1,2,3),(4,5,6)];b=(7,8);[x+(y,)
for x,y in zip(a,b)]'
100 loops, best of 3: 1.44 usec per loop
And my
SOLVED! I just found it out
> I'm searching for a nice way to merge a list of
> tuples with another tuple or list. Short example:
> a = [(1,2,3), (4,5,6)]
> b = (7,8)
>
> After the merging I would like to have an output like:
> a = [(1,2,3,7), (4,5,6)]
The following code solves the problem:
>
I used the following code to add a single fixed value to both tuples.
But this is still not what I want...
>>>a = [(1,2,3), (4,5,6)]
>>>b = 1
>>>a = map(tuple, map(lambda x: x + [1], map(list, a)))
>>>a
[(1, 2, 3, 1), (4, 5, 6, 1)]
What I need is:
>>>a = [(1,2,3), (4,5,6)]
>>>b = (7,8)
>>> a = COD
On Oct 19, 8:35 pm, James Mills wrote:
> On Wed, Oct 20, 2010 at 10:16 AM, Daniel Wagner
>
> wrote:
> > My short question: I'm searching for a nice way to merge a list of
> > tuples with another tuple or list. Short example:
> > a = [(1,2,3), (4,5,6)]
> &g
ut like:
a = [(1,2,3,7), (4,5,6)]
It was possible for me to create this output using a "for i in a"
technique but I think this isn't a very nice way and there should
exist a solution using the map(), zip()-functions
I appreciate any hints how to solve this problem efficiently.