On Oct 27, 10:29 pm, Minh Nguyen <[email protected]> wrote:
> Hi Marusia,
>
> On Thu, Oct 28, 2010 at 7:02 AM, m.rebolledo
>
> <[email protected]> wrote:
> > Hello,
> > how to do the union of several lists (more than two)?
>
> Lists are multisets, so I assume you mean to combine several lists
> into one, while retaining duplicate elements. You could do so using
> the list concatenation operator "+":
>
> sage: L1 = [2, 3, 5, 7, 11]
> sage: L2 = ["a", "b", "c", 13]
> sage: L3 = [1/2, 1/3, 1/4]
> sage: L1 + L2 + L3
> [2, 3, 5, 7, 11, 'a', 'b', 'c', 13, 1/2, 1/3, 1/4]
>
Hi,
just as a sidenote, this might make people write this:
L = sum( a list of list, [] )
which is correct but quite inefficient.
Compare the following:
timeit('L = sum([[0] for i in range(10000)], [])')
and
timeit('L = []\nfor i in range(10000): L += [0]')
Regards
Yann
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org