Python complaints

Charles Boncelet boncelet at udel.edu
Wed Dec 15 05:20:35 EST 1999


Mike Fletcher wrote:
> 
> for first, second, third in [
>         (a/x, a**2, y)
>                 for a in listone,
>                 for y in [(l3val**4) for l3val in listthree],
>                 for x in [(2**math.PI**l4val) for l4val in listfour],
> ]:
>         print first, second, third
> 
> Or something similar is probably what people are hyped about.  I.e. complex
> parallel processing of multiple lists with multiple levels of comprehension
> (ww?).  Note, I'm sure someone will want to add "for i indexing x in []"
> syntax to this construct :) .

Well, I like this syntax a helluva lot more than map(lambda x: f(x),
list) etc. But I wonder if adding these things might take Python too far
down the
dark side.  

However, if adding list comprehension allows Python to remove lambda and
map, then maybe that's a risk worth taking...

However, I often want more list processing functionality: Eg. 

>>> from math import sin
>>> sin([1,2,3])

returns a "TypeError: illegal argument type for built-in operation"
(instead of saying "sin() requires a single number for an argument, not 
a list", but that's another story) rather than what I wanted:

[sin(1), sin(2), sin(3)]

(Note, if I said "from Numeric import sin" it works just fine.)

I think all functions that operate on single things should be able to
operate on a list of things and return a list of things. (Are there
obvious reasons why this paradigm can't work?) Consider,

>>> l = [1,2,3]
>>> m = [l,l]
>>> len(l)
2
>>> len(m)
3

I want len(m) to return [3,3]. And I want: max(len(m)) to return 3, etc.

(Yes, I know I can write my version of
len and have it return whatever I want it to, but I am wondering
about the paradigm and why it is not generally true.)

-- 
Charles Boncelet <boncelet at udel.edu>
University of Delaware
Newark DE 19716 USA
http://www.eecis.udel.edu/~boncelet/




More information about the Python-list mailing list