Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #34188
| References | <6049bc85-6f8e-429b-a855-ecef47a9d28e@googlegroups.com> <k9j0k6$e4l$1@reader1.panix.com> |
|---|---|
| Date | 2012-12-04 07:17 +1100 |
| Subject | Re: Conversion of List of Tuples |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.439.1354565829.29569.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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