Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.040 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'problem:': 0.07; '[3]:': 0.09; '24,': 0.16; 'comp': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:Converting': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'bit': 0.19; 'pointed': 0.19; '>>>': 0.22; 'simpler': 0.24; 'skip:l 30': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'subject:list': 0.30; 'message- id:@mail.gmail.com': 0.30; 'subject:lists': 0.35; 'received:google.com': 0.35; 'list': 0.37; 'same.': 0.38; 'solving': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'simple': 0.61; 'complete': 0.62; 'different': 0.65; 'jul': 0.74; 'rafael': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=e6QakPIVugvAu+LZqyCLeYX2ovCfv/+AryeWYmvg7cI=; b=ALAXVwOhoCS4HKNZkgK9SciX19Ono16D68opC68rsudF3MiCOV5tYKJaPs+aJU8tWY JW5GW3IWccw43j0coXStKAcyF2NgrMvq0EzOrCWAOl7rfKWIYmosJG9Ftm+2ADEt1D8G aZTcR3svSeiPVhKZhNZTNdd9GsoUeub/3aE1PjbERwt724c01NIVWH6CqSmuhVegI0Yo CMIjhLdjd70gKKjBp/kG4nx08jAEEwhmpSlUb0DkZgtc9vpgzx8HvuZZ2XxUR4WW4btm rxoYHMHz8/HwIKOpI6s1VbyWkkf0tVPwoxApPXSybbfUAqY78YAFp0YDHku64Pqs6/pP qonw== MIME-Version: 1.0 X-Received: by 10.52.227.69 with SMTP id ry5mr68950vdc.83.1374644436128; Tue, 23 Jul 2013 22:40:36 -0700 (PDT) In-Reply-To: <51EF04F7.9040401@gmail.com> References: <51EF04F7.9040401@gmail.com> Date: Wed, 24 Jul 2013 15:40:36 +1000 Subject: Re: Converting a list of lists to a single list From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1374644439 news.xs4all.nl 15899 [2001:888:2000:d::a6]:42760 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:51118 On Wed, Jul 24, 2013 at 8:34 AM, Rafael Dur=E1n Casta=F1eda wrote: > In [3]: [ y for y in itertools.chain.from_iterable(x)] > Out[3]: ['A0', 'A1', 'A2', 'B0', 'B1', 'B2', 'C0', 'C1', 'C2'] Complete aside, given that this has already been pointed out as solving a different problem: Any time you see a list comp that just does "[ x for x in foo ]", check to see if it can be replaced by a simple list constructor: >>> [ y for y in itertools.chain.from_iterable(x)] ['A0', 'A1', 'A2', 'B0', 'B1', 'B2', 'C0', 'C1', 'C2'] >>> list(itertools.chain.from_iterable(x)) ['A0', 'A1', 'A2', 'B0', 'B1', 'B2', 'C0', 'C1', 'C2'] A bit simpler and achieves the same. ChrisA