Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #51108
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!newsfeed0.kamp.net!newsfeed.kamp.net!feeder1.cambriumusenet.nl!82.197.223.108.MISMATCH!feeder2.cambriumusenet.nl!feeder3.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.81.MISMATCH!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <z@etiol.net> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.093 |
| X-Spam-Evidence | '*H*': 0.85; '*S*': 0.03; 'else:': 0.03; 'def': 0.12; 'itertools': 0.16; 'subject:Converting': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'import': 0.22; 'looks': 0.24; 'this:': 0.26; 'header :In-Reply-To:1': 0.27; 'subject:list': 0.30; 'message- id:@mail.gmail.com': 0.30; 'convert': 0.35; 'subject:lists': 0.35; 'received:google.com': 0.35; 'list': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'chain': 0.60; 'july': 0.63; "how's": 0.74; 'lists:': 0.91; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:x-originating-ip:in-reply-to:references:from :date:x-google-sender-auth:message-id:subject:to:content-type; bh=I4pfrdWBKAgl/dv5ZuqsmC3t6nJLiQsf6k+40qf1BmQ=; b=pxcsdqKiYfzccDVJ1aD3xiW1YejyaQO6xA7o15u82qmkrCa1eftuYmwmfi9tFOujlo tt9VKpwYijKEUNglSDgR1dxJebVuy8QBuB8fIMsUG7iUdkrelDvKOe6xKgmYoOndmkUJ U3h7bQ5sKr4qQaIehc5p4BLseUwsG5yrgRnrGiwWHEvU1UnUYeXbArXWrkMvDHwky0BP GH2VERWTsCOYDH9w6pONxuptXsApOT8M79XdP4XM23blEFUzERPt/Qg3t5yPODXdyh8x Y8oKJP0dALyN/7Sr/UPPZZYKlVtvRdk/l3+FefIPumoBn+tk041UtzcIQk/Px9USZ5JO NkqA== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:sender:x-originating-ip:in-reply-to:references:from :date:x-google-sender-auth:message-id:subject:to:content-type :x-gm-message-state; bh=I4pfrdWBKAgl/dv5ZuqsmC3t6nJLiQsf6k+40qf1BmQ=; b=kPc5PHD92ZFsRmX4t3lD74w88hYA0pJ8PB+v6WU7YqXQ3YQb5oYkM5EP4f/gmjUJNZ lmREMoXACQ76Su813hDHSK+8B4o3MFjIdvbelfzClj4im7bwjZZN6tVMxdrRzSFDFj3L 0Zl4vqgLPAM/bq4nCSkbF3cIxfqSCriMS7GNDME9dgipEqhYegCE5TcuapnI2lbccofe keXPg1NECpfs1Y1cT8Gf7FxSr/s5IEaB6u3nuG9y8l0qjBfztqFpZVh2kfnKgCUb1WAa lTFI+kN7SekjqiT3N1SfIt0Xu6Ic/EammnsUbu/xuSMgPmLXlTNnOkFf2palbxATXU9A AzUw== |
| X-Received | by 10.195.12.202 with SMTP id es10mr24993622wjd.17.1374619779095; Tue, 23 Jul 2013 15:49:39 -0700 (PDT) |
| MIME-Version | 1.0 |
| Sender | z@etiol.net |
| X-Originating-IP | [190.47.101.237] |
| In-Reply-To | <ee6f5c48-6cb1-498f-813a-be2eef5411fc@googlegroups.com> |
| References | <ee6f5c48-6cb1-498f-813a-be2eef5411fc@googlegroups.com> |
| From | Zero Piraeus <schesis@gmail.com> |
| Date | Tue, 23 Jul 2013 18:49:19 -0400 |
| X-Google-Sender-Auth | g-uQ09rivnea4ePs92OXhJf5WrM |
| Subject | Re: Converting a list of lists to a single list |
| To | python-list@python.org |
| Content-Type | text/plain; charset=UTF-8 |
| X-Gm-Message-State | ALoCoQlkLlziD0FnOY6IOrCkvqX9G2KFsBpy9vfSIhQQsS3Yry3Sz45J3XzJErW1HeP1iuH7p7WW |
| 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.5018.1374620275.3114.python-list@python.org> (permalink) |
| Lines | 28 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1374620275 news.xs4all.nl 15960 [2001:888:2000:d::a6]:46328 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:51108 |
Show key headers only | View raw
:
On 23 July 2013 17:52, <steve@divillo.com> wrote:
>
> Say I have three lists:
>
> [[A0,A1,A2], [B0,B1,B2] [C0,C1,C2]]
>
> I would like to convert those to a single list that looks like this:
>
[A0,B0,C0,C1,C2,B1,C0,C1,C2,B2,C0,C1,C2,A1,B0,C0,C1,C2,B1,C0,C1,C2,B2,C0,C1,C2,A2,B0,C0,C1,C2,B1,C0,C1,C2,B2,C0,C1,C2]
How's this:
from itertools import chain
def treeify(seq):
if seq:
return list(chain(*([x] + treeify(seq[1:]) for x in seq[0])))
else:
return []
>>> treeify([['A0', 'A1', 'A2'], ['B0', 'B1', 'B2'], ['C0', 'C1', 'C2']])
['A0', 'B0', 'C0', 'C1', 'C2', 'B1', 'C0', 'C1', 'C2', 'B2', 'C0', 'C1', 'C2',
'A1', 'B0', 'C0', 'C1', 'C2', 'B1', 'C0', 'C1', 'C2', 'B2', 'C0', 'C1', 'C2',
'A2', 'B0', 'C0', 'C1', 'C2', 'B1', 'C0', 'C1', 'C2', 'B2', 'C0', 'C1', 'C2']
-[]z.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Converting a list of lists to a single list steve@divillo.com - 2013-07-23 14:52 -0700 Re: Converting a list of lists to a single list Rafael Durán Castañeda <rafadurancastaneda@gmail.com> - 2013-07-24 00:34 +0200 Re: Converting a list of lists to a single list MRAB <python@mrabarnett.plus.com> - 2013-07-23 23:52 +0100 Re: Converting a list of lists to a single list Zero Piraeus <schesis@gmail.com> - 2013-07-23 18:49 -0400 Re: Converting a list of lists to a single list Terry Reedy <tjreedy@udel.edu> - 2013-07-23 19:02 -0400 Re: Converting a list of lists to a single list Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-07-23 20:28 -0400 Re: Converting a list of lists to a single list Chris Angelico <rosuav@gmail.com> - 2013-07-24 15:40 +1000 Re: Converting a list of lists to a single list Terry Reedy <tjreedy@udel.edu> - 2013-07-24 11:56 -0400 Re: Converting a list of lists to a single list steve@divillo.com - 2013-07-24 11:11 -0700
csiph-web