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


Groups > comp.lang.python > #5358

Re: Converting a set into list

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '(new)': 0.09; '>>>>': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'wrote:': 0.14; 'iterable,': 0.16; 'mylist': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'subject:Converting': 0.16; 'subject:set': 0.16; 'converting': 0.16; 'object,': 0.19; 'subject:list': 0.22; 'worked': 0.24; 'skip:[ 10': 0.26; 'list': 0.30; 'from:addr:web.de': 0.31; 'to:addr:python-list': 0.32; 'another': 0.32; "i've": 0.33; 'creates': 0.33; 'header:X-Complaints-To:1': 0.34; 'actually': 0.34; 'there': 0.35; 'list.': 0.35; 'too': 0.36; 'received:org': 0.38; 'set': 0.39; 'to:addr:python.org': 0.39; 'header:Mime- Version:1': 0.39; 'solution': 0.40; 'would': 0.40; 'header:Received:5': 0.40; 'here.': 0.68
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: Converting a set into list
Date Sat, 14 May 2011 11:33:15 +0200
Organization None
References <iqlgj4$iet$1@speranza.aioe.org>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p5084a247.dip.t-dialin.net
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1543.1305365545.9059.python-list@python.org> (permalink)
Lines 27
NNTP-Posting-Host 82.94.164.166
X-Trace 1305365545 news.xs4all.nl 41110 [::ffff:82.94.164.166]:40720
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:5358

Show key headers only | View raw


TheSaint wrote:

> I've stumble to find a solution to get a list from a set
> 
> <code>
> 
>>>> aa= ['a','b','c','f']
>>>> aa
> ['a', 'b', 'c', 'f']
>>>> set(aa)

To clarify: this creates a new object, so aa is still a list.

> {'a', 'c', 'b', 'f'}
>>>> [k for k in aa]
> ['a', 'b', 'c', 'f']

So you are actually converting a list to a (new) list here. Of course it 
would have worked with a set or an arbitrary iterable, too.

> </code>
> I repute the comprehension list too expensive, is there another method?
 
mylist = list(myset)

Do you notice the similarity to converting a list to a set?

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


Thread

Converting a set into list TheSaint <nobody@nowhere.net.no> - 2011-05-14 17:02 +0800
  Re: Converting a set into list Peter Otten <__peter__@web.de> - 2011-05-14 11:33 +0200
    Re: Converting a set into list TheSaint <nobody@nowhere.net.no> - 2011-05-14 22:14 +0800
      Re: Converting a set into list Chris Angelico <rosuav@gmail.com> - 2011-05-15 04:22 +1000
  Re: Converting a set into list Ben Finney <ben+python@benfinney.id.au> - 2011-05-15 00:12 +1000
    Re: Converting a set into list TheSaint <nobody@nowhere.net.no> - 2011-05-14 22:51 +0800
      Re: Converting a set into list Ben Finney <ben+python@benfinney.id.au> - 2011-05-15 09:21 +1000
        Re: Converting a set into list Chris Torek <nospam@torek.net> - 2011-05-15 02:11 +0000
          Re: Converting a set into list SigmundV <sigmundv@gmail.com> - 2011-05-15 04:18 -0700
            Re: Converting a set into list SigmundV <sigmundv@gmail.com> - 2011-05-15 04:23 -0700
            Re: Converting a set into list TheSaint <nobody@nowhere.net.no> - 2011-05-15 23:56 +0800
              Re: Converting a set into list Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-05-15 22:27 +0200
                Re: Converting a set into list Daniel Kluev <dan.kluev@gmail.com> - 2011-05-16 13:37 +1100
                Re: Converting a set into list Peter Otten <__peter__@web.de> - 2011-05-16 08:34 +0200
                Re: Converting a set into list TheSaint <nobody@nowhere.net.no> - 2011-05-16 22:23 +0800
                Re: Converting a set into list Ben Finney <ben+python@benfinney.id.au> - 2011-05-17 10:33 +1000
            Re: Converting a set into list Roy Smith <roy@panix.com> - 2011-05-15 13:07 -0400
          Re: Converting a set into list TheSaint <nobody@nowhere.net.no> - 2011-05-16 00:05 +0800
            Re: Converting a set into list Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-15 16:28 +0000
              Re: Converting a set into list TheSaint <nobody@nowhere.net.no> - 2011-05-16 00:35 +0800
          Re: Converting a set into list Duncan Booth <duncan.booth@invalid.invalid> - 2011-05-16 10:24 +0000
            Re: Converting a set into list Chris Torek <nospam@torek.net> - 2011-05-17 01:07 +0000

csiph-web