[Python-ideas] Adding "Typed" collections/iterators to Python

Nathan Rice nathan.alexander.rice at gmail.com
Mon Dec 19 14:52:33 CET 2011


>> L2 = [X(e) for e in L1]>> L3 = [Y(e) for e in L2]>> vs>> L2 = X(L1) # assuming X has been updated to work in both vector/scalar>> L3 = Y(L2) # context...>>> L = ['a', 'bc', ['ada', 'a']]>> What is len(L)? 3 or [1, 2, 2] or [1, 2, [3, 1]]?>>>> L2 = [Z(Y(X(e))) for e in L1]>> vs>> L2 = Z(Y(X(L1)))>>>> L2 = [e.X().Y().Z() for e in L1]>> vs>> L2 = L1.X().Y().Z() # assuming vectorized versions of member methods>> #are folded into the collection via the mixin.>>> What is L.count('a')? 1 or [1, 0, 1] or [1, 0, [2, 1]]?

A fair concern; if the vectorized version of the child method were
given the same name as the child method, I agree that this could
result in ambiguity.

There are multiple ways that member methods could be made available on
the collection, including a proxy attribute, renaming, etc.
...
>>  I find
>> using operator&  functools _far_ clearer in intent than using lambda,
>>
>> _and it works right now_, which was the point I was trying to make
>> here.
>
>
> I find using list comprehensions and generator expressions even more
> clearer.

In general I think comprehensions are superior to map because they are
more intuitive.  Based on my experience reading code in the community
I think that is well supported.

Sadly, even though I have issues with the way they are used in many
cases, lambdas are superior to a lot of other options because they are
simple and cover many use cases.  When used inline with simple
expressions they provide a lot of mileage.



More information about the Python-ideas mailing list