fast sub list operations
Robin Becker
robin at jessikat.fsnet.co.uk
Tue Oct 16 13:29:32 EDT 2001
In message <15308.17945.822446.173014 at beluga.mojam.com>, Skip Montanaro
<skip at pobox.com> writes
> >> >>> zip([1,2,3],[7,8,9])
> >> [(1, 7), (2, 8), (3, 9)]
>
> Robin> I know about NumPy and like it a lot, but it's a bit heavyweight
> Robin> for what we need. I also know about zip and apart from there
> Robin> being no unzip it doesn't join up my list which should look like
> Robin> [1,7,2,8,3,9].
>
>Whoops... Try this instead:
>
> >>> l = zip([1,2,3],[7,8,9])
> >>> reduce(operator.add, l, ())
> (1, 7, 2, 8, 3, 9)
>
>Obviously, if you need a list, you can apply that function to the result.
>
that's nice from pairs to a simple tuple
--
Robin Becker
More information about the Python-list
mailing list