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


Groups > comp.lang.python > #34188

Re: Conversion of List of Tuples

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.062
X-Spam-Evidence '*H*': 0.88; '*S*': 0.00; 'that?': 0.05; 'terms,': 0.09; 'tuple': 0.09; 'dec': 0.15; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'structure.': 0.16; 'wrote:': 0.17; 'question.': 0.20; 'written': 0.20; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'received:209.85.210.46': 0.27; 'message- id:@mail.gmail.com': 0.27; 'writes:': 0.29; 'asking': 0.32; 'subject:List': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'received:209.85': 0.35; 'item': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'list,': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'group,': 0.60; 'john': 0.60; 'skip:n 10': 0.63; 'email addr:gmail.com': 0.63; 'more': 0.63; 'here': 0.65; 'dear': 0.66; 'as:': 0.75
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; bh=m/jE4FQ/ROd3wusgd7cNfyvqiAOslSktXbt6aVsy3uw=; b=Q0A2voGbQXg3/NwiC9ytHDcvXuwKyH82sjInumQqcB+TScOPtn//jpxVVBG5yLn7oT ptA5hpy56KnyqWb6/DSLFBOnGUixrCuFPRe+LR9C6eg5symodOwpXls99N9NgMmt+UzP zSg1tPr7mwwTYRimbiL18C0ri5Ok6DkNlDimnprKJlsiwmmxR8VVwfR/jTK99v7JpCNV yVEWbQQPG+4dow7JHCWwddTgt5THhvAk1CQiRiShIWwYknbYiVuhbrY9NML8Trpdu/x2 EUjDh/hvJNHoFF27ac/NxZ6Pqtr29TbMXTX4CMKjJYrA9Hi57tZ8u5B181emHY+IRlY8 TtMw==
MIME-Version 1.0
In-Reply-To <k9j0k6$e4l$1@reader1.panix.com>
References <6049bc85-6f8e-429b-a855-ecef47a9d28e@googlegroups.com> <k9j0k6$e4l$1@reader1.panix.com>
Date Tue, 4 Dec 2012 07:17:05 +1100
Subject Re: Conversion of List of Tuples
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
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.439.1354565829.29569.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1354565829 news.xs4all.nl 6952 [2001:888:2000:d::a6]:43833
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:34188

Show key headers only | View raw


On Tue, Dec 4, 2012 at 7:04 AM, John Gordon <gordon@panix.com> wrote:
> In <6049bc85-6f8e-429b-a855-ecef47a9d28e@googlegroups.com> subhabangalore@gmail.com writes:
>
>> Dear Group,
>
>> I have a tuple of list as,
>
>> tup_list=[(1,2), (3,4)]
>> Now if I want to covert as a simple list,
>
>> list=[1,2,3,4]
>
>> how may I do that?
>
> new_list = []
>
> for t in tup_list:
>     for item in t:
>         new_list.append(item)

Which can be written more succintly as:

new_list = []
for t in tup_list:
    new_list.extend(t)

In more general terms, what you're looking to do here is *flatten*
your structure. Not sure if that would have helped in the web search
that you doubtless did before asking this question. :)

ChrisA

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


Thread

Conversion of List of Tuples subhabangalore@gmail.com - 2012-12-03 11:58 -0800
  Re: Conversion of List of Tuples John Gordon <gordon@panix.com> - 2012-12-03 20:04 +0000
    Re: Conversion of List of Tuples MRAB <python@mrabarnett.plus.com> - 2012-12-03 20:13 +0000
    Re: Conversion of List of Tuples Chris Angelico <rosuav@gmail.com> - 2012-12-04 07:17 +1100
  Re: Conversion of List of Tuples Chris Kaynor <ckaynor@zindagigames.com> - 2012-12-03 12:10 -0800
  Re: Conversion of List of Tuples subhabangalore@gmail.com - 2012-12-03 13:14 -0800
    Re: Conversion of List of Tuples John Gordon <gordon@panix.com> - 2012-12-03 22:02 +0000
    Re: Conversion of List of Tuples Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-03 22:11 +0000
      Re: Conversion of List of Tuples Walter Hurry <walterhurry@lavabit.com> - 2012-12-03 22:43 +0000
  Re: Conversion of List of Tuples Gary Herron <gherron@digipen.edu> - 2012-12-03 12:08 -0800
  Re: Conversion of List of Tuples Alexander Blinne <news@blinne.net> - 2012-12-04 10:44 +0100
    Re: Conversion of List of Tuples Hans Mulder <hansmu@xs4all.nl> - 2012-12-04 12:45 +0100
      Re: Conversion of List of Tuples Neil Cerutti <neilc@norwich.edu> - 2012-12-04 13:54 +0000

csiph-web