Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list)

Chris Angelico rosuav at gmail.com
Thu Mar 27 22:24:15 EDT 2014


On Fri, Mar 28, 2014 at 9:14 AM, Mark H Harris <harrismh777 at gmail.com> wrote:
> Your question has a somewhat false premise. They *really do* want to learn
> them, and they are frustrated with the time and attention it takes. The
> argument is also from analogy, which in this case is almost similar but not
> quite.
>
> Now, there is no royal road to geometry, opera, the violin, and the piano
> (I'm a pianist, and flutist--and an amateur composer). All of these fine
> arts take time, there is just no getting around it.

How many hours of practice have you put into musical study? The usual
estimate is ten thousand hours to achieve mastery. If you're an
amateur composer, you've probably put in rather a lot of hours. (I am
one also, and I'm pretty sure I've put in rather a lot more than 10K
hours in various musical fields.) But if you just want to sing hymns
in church, you don't need *or want* to put in that much practice. Why
should that sort of person want to learn/master opera?

I used opera as an example because I'm about to dive into another one
- this Tuesday is bump-in (getting all our scenery into the theatre),
and we open before a real audience on April 5th. [1] In that
production are a number of really REALLY awesome people (Ron Pidcock,
Jenny Wakefield, Lydia Kovesi, Andrea Tappe...) who've put in huge
numbers of hours to master the singing, dancing, etc required for the
roles. Me? I'm able to sing, but I don't have the time (or the money)
to get *that* good, so I don't audition for roles. I'm content to work
lighting instead.

Conversely, I'm a master of networking. I've put in plenty of hours to
achieve mastery, and continue to do so. One of our sopranos was having
trouble with her home network, and I swung by and gave her a hand. She
doesn't want or need to understand what's going on, yet she uses and
appreciates her wireless network. She *really does not* want to learn
networking, or programming, just as I do not want to learn operatic
singing, or how to build a death ray. Python can come in handy for
her, but she is NOT the "normal user" for Python - and yet she fits
into your description, below.

> People want to use their computer. They want to solve problems with it...
> and frankly, they would like to know how to program it, if there where some
> royal road, or fast track, or short and easy tutorial. I know lots of people
> that will sit down and try (with a cup of Java) and hack it out if they have
> a good short book.

There might be a short and easy tutorial "Python for people who
already know Pike" (except that there won't be much call for it).
There could possibly be "Python for mathematicians", because maths
requires a similar vigor. There might even be "Python for brain
surgeons". But there won't be "Python for people who know nothing" as
a simple tutorial. It takes skill and mastery to become a programmer,
and that doesn't come from nowhere. Transferring that skill from
another area is easier than conjuring it (and easier still if the two
areas are similar), but if someone has a similar skill already, s/he's
probably already a programmer, and so isn't part of your description.

Most people want to *use* a computer, and most certainly do *not* want
to *program* it. I know this from personal experience; plenty of
people will use electronica that they can't fiddle with - just look at
the popularity of the iphone. There might well be an app for that, but
if there isn't, well, you're going to need to go through a lot of
hoops to create it. There's no way a typical iphone user can program
his/her phone.

> Just look on the list:  Fred Sells meta language request.  He proves my
> point entirely.  I have not responded yet... thought I would wait a bit...
> but look what he is after.  Go read it.

I've read it (although not Terry's response, yet). He wants to create
a DSL. I didn't respond because I know someone else will do so better
(also, it was 8AM and I'd been up most of the night learning about
systemd - making the jump now that Debian's settling on it, so it's
time to port my Upstart jobs and knowledge), but my guess would be
that he's not really looking for a *programming* language, but a *page
description* language. Something in the same field as HTML, not
Python.

> But, I don't disagree with you Chris, and I have myself some of the same
> concerns really. I'm finding the path harder than I thought it would be.
> Well, its hard enough just getting other people who are experts to buy into
> it.  Its going to be an uphill climb, for sure.

Programming forces you to understand programming. Even if you just use
Python as a super-calculator (which, incidentally, I often do), you're
still going to end up running into edge cases that force you to
comprehend what you're doing:

>>> 1e16+3-1e16
4.0

Common sense says it ought to be 3.0, but it ain't. IEEE floating
point explains why this happens, but that's getting technical.

If you don't want to write code, get a calculator. If you want to
write code, learn at least something of programming, and understand
that Python's syntax is not aimed at the person who knows nothing. A
car's engine usually isn't tuned for 10km/h running; you have to get
up a bit of speed before it becomes more efficient. Why is it so wrong
for Python to expect the same?

ChrisA

[1] http://gilbertandsullivan.org.au/ - come see us if you're in Melbourne!



More information about the Python-list mailing list