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


Groups > comp.lang.python > #31926

Re: can we append a list with another list in Python ?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!border1.nntp.ams.giganews.com!nntp.giganews.com!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <prvs=6367b9a2d=jeanmichel@sequans.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.191
X-Spam-Level *
X-Spam-Evidence '*H*': 0.62; '*S*': 0.00; 'subject:Python': 0.05; '[1,': 0.09; 'alist': 0.16; 'sublist': 0.16; 'cheers,': 0.23; 'to:2**1': 0.23; 'header:In-Reply-To:1': 0.25; 'subject:list': 0.28; 'though.': 0.29; 'subject: ?': 0.30; 'lists': 0.31; 'asking': 0.32; '-----': 0.32; 'problem': 0.33; 'to:addr:python- list': 0.33; 'done': 0.34; 'list': 0.35; 'list.': 0.35; 'but': 0.36; "i'll": 0.36; 'subject:with': 0.36; 'thank': 0.36; 'item': 0.37; 'rather': 0.37; 'subject:: ': 0.38; 'store': 0.38; 'description': 0.39; 'to:addr:python.org': 0.39; 'you.': 0.61; 'received:194': 0.61; 'different': 0.63; 'information': 0.63; 'person,': 0.65; 'disclose': 0.69; 'notice:': 0.71; 'privileged.': 0.72; 'trick.': 0.84; 'medium.': 0.91
X-IronPort-AV E=Sophos;i="4.80,635,1344204000"; d="scan'208";a="821710"
X-Virus-Scanned amavisd-new at zimbra.sequans.com
Date Tue, 23 Oct 2012 13:07:45 +0200 (CEST)
From Jean-Michel Pichavant <jeanmichel@sequans.com>
To inshu chauhan <insideshoes@gmail.com>, python-list@python.org
In-Reply-To <CAFqGZRFUk0D_xnTZ19t6pK1dfCDKXct7iNps6MT6yjVFpF+bMw@mail.gmail.com>
Subject Re: can we append a list with another list in Python ?
MIME-Version 1.0
X-Mailer Zimbra 7.2.0_GA_2669 (ZimbraWebClient - GC7 (Linux)/7.2.0_GA_2669)
Content-Type text/plain; charset="utf-8"
Content-Transfer-Encoding base64
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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.2660.1350990448.27098.python-list@python.org> (permalink)
Lines 16
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1350990448 news.xs4all.nl 6880 [2001:888:2000:d::a6]:43669
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:31926

Show key headers only | View raw


----- Original Message ----- 

> Thankyou.. but my problem is different than simply joining 2 lists
> and it is done now :)....


A lot of people though you were asking for joining lists, you description was misleading.

I'll take a guess: you want to flatten a list of list.
"Nested" list comprehensions can do the trick.

aList =[[1,5], [2,'a']]
[item for sublist in aList for item in sublist]

...
[1, 5, 2, 'a']
       
I find it rather difficult to read though.

Cheers,

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

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


Thread

Re: can we append a list with another list in Python ? Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-10-23 13:07 +0200

csiph-web