Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #10996

Re: how to separate a list into two lists?

References <mailman.1983.1312650424.1164.python-list@python.org> <mfor37tgmao0e5mlvllj02kgo2esp25dcd@4ax.com>
Date 2011-08-07 02:05 +0100
Subject Re: how to separate a list into two lists?
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2002.1312679117.1164.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, Aug 7, 2011 at 1:58 AM, Tim Roberts <timr@probo.com> wrote:
> I did momentarily consider the following slimy solution:
>  L1 = dict(L).keys()
>  L2 = dict(L).values()
> but that reorders the tuples.  They still correspond, but in a different
> order.
>

Which can be overcome with collections.OrderedDict. But what's dict(L)
going to do? It's going to loop over L, more than once in fact.

I guess the real question is: Why do you wish to avoid a loop?

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

how to separate a list into two lists? smith jack <thinke365@gmail.com> - 2011-08-07 01:07 +0800
  Re: how to separate a list into two lists? bud <only@fleshwound.org> - 2011-08-06 18:13 +0000
    Re: how to separate a list into two lists? Gelonida N <gelonida@gmail.com> - 2011-08-06 22:00 +0200
      Re: how to separate a list into two lists? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-07 10:07 +1000
        Re: how to separate a list into two lists? Gelonida N <gelonida@gmail.com> - 2011-08-07 19:11 +0200
  Re: how to separate a list into two lists? Tim Roberts <timr@probo.com> - 2011-08-06 17:58 -0700
    Re: how to separate a list into two lists? Chris Angelico <rosuav@gmail.com> - 2011-08-07 02:05 +0100
      Re: how to separate a list into two lists? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-07 11:35 +1000
  Re: how to separate a list into two lists? Paul Rubin <no.email@nospam.invalid> - 2011-08-06 22:29 -0700

csiph-web