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


Groups > comp.lang.python > #34225

Re: Conversion of List of Tuples

From Neil Cerutti <neilc@norwich.edu>
Newsgroups comp.lang.python
Subject Re: Conversion of List of Tuples
Date 2012-12-04 13:54 +0000
Organization Norwich University
Message-ID <ai6dkvFk3vkU4@mid.individual.net> (permalink)
References <6049bc85-6f8e-429b-a855-ecef47a9d28e@googlegroups.com> <50bdc601$0$9517$9b4e6d93@newsspool1.arcor-online.net> <50bde242$0$6947$e4fe514c@news2.news.xs4all.nl>

Show all headers | View raw


On 2012-12-04, Hans Mulder <hansmu@xs4all.nl> wrote:
> It's considered bad style to use map it you don't want the list it
> produces.
>
>> There are more ways:
>> 
>>>>> from operator import add
>>>>> reduce(add, a)
>> (1, 2, 3, 4)
>
> There's a built-in that does "reduce(operator.add"; it's called "sum":
>
>>>> sum(a, ())
> (1, 2, 3, 4)

I thought that sort of thing would cause a warning. Maybe it's
only for lists.

Here's the recipe from the itertools documentation:

def flatten(listOfLists):
    "Flatten one level of nesting"
    return chain.from_iterable(listOfLists)

-- 
Neil Cerutti

Back to comp.lang.python | Previous | NextPrevious 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