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


Groups > comp.lang.python > #69285 > unrolled thread

Howto flaten a list of lists was (Explanation of this Python language feature)

Started byMark H Harris <harrismh777@gmail.com>
First post2014-03-28 16:56 -0500
Last post2014-03-29 15:59 +0000
Articles 11 — 6 participants

Back to article view | Back to comp.lang.python


Contents

  Howto flaten a list of lists was (Explanation of this Python language feature) Mark H Harris <harrismh777@gmail.com> - 2014-03-28 16:56 -0500
    Re: Howto flaten a list of lists was (Explanation of this Python language feature) Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-28 22:12 +0000
      Re: Howto flaten a list of lists was (Explanation of this Python language feature) Mark H Harris <harrismh777@gmail.com> - 2014-03-28 17:23 -0500
        Re: Howto flaten a list of lists was (Explanation of this Python language feature) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-29 02:33 +0000
          Re: Howto flaten a list of lists was (Explanation of this Python language feature) Mark H Harris <harrismh777@gmail.com> - 2014-03-28 22:04 -0500
            Re: Howto flaten a list of lists was (Explanation of this Python language feature) Rustom Mody <rustompmody@gmail.com> - 2014-03-28 20:21 -0700
              Re: Howto flaten a list of lists was (Explanation of this Python language feature) Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-29 15:46 +0000
            Re: Howto flaten a list of lists was (Explanation of this Python language feature) Chris Angelico <rosuav@gmail.com> - 2014-03-29 14:21 +1100
              Re: Howto flaten a list of lists was (Explanation of this Python language feature) Mark H Harris <harrismh777@gmail.com> - 2014-03-28 22:39 -0500
      Re: Howto flaten a list of lists was (Explanation of this Python language feature) Mark H Harris <harrismh777@gmail.com> - 2014-03-28 17:23 -0500
      Re: Howto flaten a list of lists was (Explanation of this Python language feature) mm0fmf <none@mailinator.com> - 2014-03-29 15:59 +0000

#69285 — Howto flaten a list of lists was (Explanation of this Python language feature)

FromMark H Harris <harrismh777@gmail.com>
Date2014-03-28 16:56 -0500
SubjectHowto flaten a list of lists was (Explanation of this Python language feature)
Message-ID<lh4r6h$sqr$1@speranza.aioe.org>
On Fri, Mar 21, 2014 at 1:42 PM, vasudevram <vasudevram@gmail.com> wrote:
 >> Can anyone - maybe one of the Python language core team, or someone 
 >> with knowledge of the internals of Python - can explain why this 
 >> code works, and whether the different occurrences of the name x in 
 >> the expression, are in different scopes or not? :
 >>
 >> x = [[1,2], [3,4], [5,6]]
 >>     [x for x in x for x in x]

 > I'll give this +1 for playfulness, and -2 for lack of clarity.

 > I hope no one thinks this sort of thing is good to do in real-life code.

No. This has to be a better way to flatten lists:

 >>> from functools import reduce

 >>> import operator as λ

 >>> reduce(λ.add, l)
[1, 2, 3, 4, 5, 6, 7, 8, 9]

 >>>


marcus

[toc] | [next] | [standalone]


#69290

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-03-28 22:12 +0000
Message-ID<mailman.8676.1396044784.18130.python-list@python.org>
In reply to#69285
On 28/03/2014 21:56, Mark H Harris wrote:
> On Fri, Mar 21, 2014 at 1:42 PM, vasudevram <vasudevram@gmail.com> wrote:
>  >> Can anyone - maybe one of the Python language core team, or someone
>  >> with knowledge of the internals of Python - can explain why this >>
> code works, and whether the different occurrences of the name x in >>
> the expression, are in different scopes or not? :
>  >>
>  >> x = [[1,2], [3,4], [5,6]]
>  >>     [x for x in x for x in x]
>
>  > I'll give this +1 for playfulness, and -2 for lack of clarity.
>
>  > I hope no one thinks this sort of thing is good to do in real-life code.

Strange, I thought Dan Stromberg wrote the above.
>
> No. This has to be a better way to flatten lists:
>
>  >>> from functools import reduce
>
>  >>> import operator as λ
>
>  >>> reduce(λ.add, l)
> [1, 2, 3, 4, 5, 6, 7, 8, 9]
>

Why reinvent yet another way of flattening lists, particulary one that 
doesn't use the far more sensible:-

from operator import add

As for the stupid symbol that you're using, real programmers don't give 
a damn about such things, they prefer writing plain, simple, boring code 
that is easy to read.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

[toc] | [prev] | [next] | [standalone]


#69291

FromMark H Harris <harrismh777@gmail.com>
Date2014-03-28 17:23 -0500
Message-ID<5335F677.20605@gmail.com>
In reply to#69290
On 3/28/14 5:12 PM, Mark Lawrence wrote:
>>
>> No. This has to be a better way to flatten lists:
>>
>>  >>> from functools import reduce
>>
>>  >>> import operator as λ
>>
>>  >>> reduce(λ.add, l)
>> [1, 2, 3, 4, 5, 6, 7, 8, 9]
>>
>
> Why reinvent yet another way of flattening lists, particulary one that
> doesn't use the far more sensible:-

    { particularly }

>
> from operator import add
>
> As for the stupid symbol that you're using, real programmers don't give
> a damn about such things, they prefer writing plain, simple, boring code
> that is easy to read.

:-))    as RMS would say, "playful hacking, dude, playful hacking..."



[toc] | [prev] | [next] | [standalone]


#69294

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2014-03-29 02:33 +0000
Message-ID<533630e2$0$29994$c3e8da3$5496439d@news.astraweb.com>
In reply to#69291
Mark, please stop posting to the newsgroup comp.lang.python AND the 
mailing list python-list@python.org. They mirror each other. Your posts 
are not so important that we need to see everything twice.


-- 
Steven D'Aprano
http://import-that.dreamwidth.org/

[toc] | [prev] | [next] | [standalone]


#69296

FromMark H Harris <harrismh777@gmail.com>
Date2014-03-28 22:04 -0500
Message-ID<lh5d7f$9pe$1@speranza.aioe.org>
In reply to#69294
On 3/28/14 9:33 PM, Steven D'Aprano wrote:
> Mark, please stop posting to the newsgroup comp.lang.python AND the
> mailing list python-list@python.org. They mirror each other. Your posts
> are not so important that we need to see everything twice.

Its not my fault, Steven. Something goofy is going on. My address says 
only comp.lang.python

I have no idea why some of these messages are being duplicated on the 
mailing list. I only post to the news group.

Anyways, sorry.  I'll keep checking this.

regards,

[toc] | [prev] | [next] | [standalone]


#69299

FromRustom Mody <rustompmody@gmail.com>
Date2014-03-28 20:21 -0700
Message-ID<95aa5148-497a-49a1-9e78-2c019c36cf25@googlegroups.com>
In reply to#69296
On Saturday, March 29, 2014 8:34:19 AM UTC+5:30, Mark H. Harris wrote:
> On 3/28/14 9:33 PM, Steven D'Aprano wrote:
> > Mark, please stop posting to the newsgroup comp.lang.python AND the
> > mailing list (...). They mirror each other. Your posts
> > are not so important that we need to see everything twice.

> Its not my fault, Steven. Something goofy is going on. My address says 
> only comp.lang.python

> I have no idea why some of these messages are being duplicated on the 
> mailing list. I only post to the news group.

> Anyways, sorry.  I'll keep checking this.

> regards,

Just use the amazing, fool-safe, fail-proof google-groups.
And enjoy bliss.

[Uh... And now I need to run... Out of sprinting practice...]

[toc] | [prev] | [next] | [standalone]


#69330

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-03-29 15:46 +0000
Message-ID<mailman.8691.1396108206.18130.python-list@python.org>
In reply to#69299
On 29/03/2014 03:21, Rustom Mody wrote:
> On Saturday, March 29, 2014 8:34:19 AM UTC+5:30, Mark H. Harris wrote:
>> On 3/28/14 9:33 PM, Steven D'Aprano wrote:
>>> Mark, please stop posting to the newsgroup comp.lang.python AND the
>>> mailing list (...). They mirror each other. Your posts
>>> are not so important that we need to see everything twice.
>
>> Its not my fault, Steven. Something goofy is going on. My address says
>> only comp.lang.python
>
>> I have no idea why some of these messages are being duplicated on the
>> mailing list. I only post to the news group.
>
>> Anyways, sorry.  I'll keep checking this.
>
>> regards,
>
> Just use the amazing, fool-safe, fail-proof google-groups.
> And enjoy bliss.
>
> [Uh... And now I need to run... Out of sprinting practice...]
>

Blast, you beat me to it, and I never could sprint :)

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

[toc] | [prev] | [next] | [standalone]


#69300

FromChris Angelico <rosuav@gmail.com>
Date2014-03-29 14:21 +1100
Message-ID<mailman.8679.1396063315.18130.python-list@python.org>
In reply to#69296
On Sat, Mar 29, 2014 at 2:04 PM, Mark H Harris <harrismh777@gmail.com> wrote:
> Its not my fault, Steven. Something goofy is going on. My address says only
> comp.lang.python

Well, something's causing your messages to come out multiple times and
with different subject lines :)

ChrisA

[toc] | [prev] | [next] | [standalone]


#69302

FromMark H Harris <harrismh777@gmail.com>
Date2014-03-28 22:39 -0500
Message-ID<lh5f8g$d71$1@speranza.aioe.org>
In reply to#69300
On 3/28/14 10:21 PM, Chris Angelico wrote:
> Well, something's causing your messages to come out multiple times and
> with different subject lines :)

    I changed the subject line ( which I did twice because the first 
post said it had an error and did not post; which apparently was a lie).

    Then I posted again (this time it went without error, but came back 
duplicated.  In any case ONLY the news group was in the to: field. Very 
strange. All of this crap started happening a couple of days back when 
Thunderbird updated their client (I should know better than to accept that).

Anyway, things were supposed to be better once I switched from gg.  uh, huh.

Well, at least the line wrapping thing is fixed.

marcus

[toc] | [prev] | [next] | [standalone]


#69292

FromMark H Harris <harrismh777@gmail.com>
Date2014-03-28 17:23 -0500
Message-ID<mailman.8677.1396045443.18130.python-list@python.org>
In reply to#69290
On 3/28/14 5:12 PM, Mark Lawrence wrote:
>>
>> No. This has to be a better way to flatten lists:
>>
>>  >>> from functools import reduce
>>
>>  >>> import operator as λ
>>
>>  >>> reduce(λ.add, l)
>> [1, 2, 3, 4, 5, 6, 7, 8, 9]
>>
>
> Why reinvent yet another way of flattening lists, particulary one that
> doesn't use the far more sensible:-

    { particularly }

>
> from operator import add
>
> As for the stupid symbol that you're using, real programmers don't give
> a damn about such things, they prefer writing plain, simple, boring code
> that is easy to read.

:-))    as RMS would say, "playful hacking, dude, playful hacking..."



[toc] | [prev] | [next] | [standalone]


#69331

Frommm0fmf <none@mailinator.com>
Date2014-03-29 15:59 +0000
Message-ID<36CZu.66087$o%7.5864@fx29.am4>
In reply to#69290
On 28/03/2014 22:12, Mark Lawrence wrote:
> As for the stupid symbol that you're using, real programmers don't give
> a damn about such things, they prefer writing plain, simple, boring code
> that is easy to read

What he said.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web