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

Rustom Mody rustompmody at gmail.com
Sun Apr 6 13:31:53 EDT 2014


On Sunday, April 6, 2014 10:22:21 PM UTC+5:30, Steven D'Aprano wrote:
> On Sun, 06 Apr 2014 12:05:16 +0300, Marko Rauhamaa wrote:

> > Mark H Harris :
> >> On 4/4/14 4:53 AM, Steven D'Aprano wrote:
> >>> Python is not a computer-science-ey language.
> >> Every programming language is interesting from a comp sci standpoint.
> >> Some are more useful for research; python is one of those.
> >> For what reasons do you disagree?
> > Computer science doesn't mean "anything related to computers."
> > Physicists typically couldn't care less about your heating up your lunch
> > in the microwave oven. Similarly, computer scientists aren't interested
> > in the mundane applications of their lofty research topics.
> > Python, BTW, is perfectly suitable for computer science. 

> I don't think it is. Python is not a pure functional language, so it's 
> very difficult to prove anything about the code apart from running it. 
> For example, see Brett Cannon's master's thesis, where he essentially 
> demonstrates that:

> - you can't do compile-time type inference of general types in Python;

> - although you can infer a very small amount of information about a 
>   few built-in types;

> - adding specialized byte-codes to handle those types gives, at best,
>   a marginal performance boost, and sometimes even slows code down.

> To quote from the conclusion:

>    "Introducing over 3,000 lines of new C code to Python's compiler 
>     to get, at best, a 1% improvement is in no way justified. The 
>     level of added complexity that would be introduced into the
>     compilation step would definitely need to lead to a noticeable
>     performance improvement, the 5% that was the goal, to justify the
>     cost of code maintenance."

> http://citeseerx.ist.psu.edu/viewdoc/download?
> doi=10.1.1.90.3231&rep=rep1&type=pdf

Thanks for the link.

It think however you are reading it more widely than intended.
The appropriate context is a few paras below:

| In the end, it seems that Python, as a language, is not geared towards
| type inference. Its flexibility, considered a great strength,
| interferes with how extensive type inference can be performed. Without
| a significant change to the language, type inference is not worth the
| hassle of implementation

So...
Yes if CS begins and ends with type-inference then your conclusion would be 
valid. However consider that some of the things that people did around 40 years
ago and do today

- use FORTRAN for numerical/simulation work --  now use scipy/sage etc
- NLP with Lisp/Prolog -- look at Nltk
- ??? with Data Analysis in Pandas
- Scheme (basis for programming pedagogy, semantics research) -> Python

you can add/multiply ad libitum

Yeah you covered this in your (2) as "...just a tool..."

Ask some recent PhD about what is for you "just" an almost irrelevant
tool and you are very likely to find that that choice may well have
been the difference between completing the research and giving up.

I think python wins because it (usually) lets people do their thing
(includes but not limited to CS-research)
and gets out of the way.  To say therefore that it is irrelevant to the 
research is a strange inversion of its advantages.

[Or simply just switch to C++ for 3 months and report back with
the increment in your white-hair-count]


In short, I just dispute your 'just'!



More information about the Python-list mailing list