fastest way to merge lists.

Aahz Maruch aahz at netcom.com
Sun Jan 9 10:56:29 EST 2000


In article <000201bf5a6c$1a133f20$f62d153f at tim>,
Tim Peters <tim_one at email.msn.com> wrote:
>
>Can't beat it, asymptotically speaking -- it's a linear-time algorithm.
>Practically speaking, Python's dicts are highly optimized too.  You can save
>a little typing via e.g.
>
>for s in list1, list2, list3, list4, list5:
>    for x in s:
>        d[x] = 1

In practice, I know that the integer "1" is a cached, unique object, but
that's an implementation detail that I prefer not to rely on.  I
therefore almost always would use "d[x] = None"; that's particularly
true if I *might* want to attach data to it later, in addition to making
it clear that I'm interested only in the dictionary keys.
--
                      --- Aahz (@netcom.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

Have a *HAPPY* day!!!!!!!!!!



More information about the Python-list mailing list