[Python-ideas] Fast sum() for non-numbers

Ron Adam ron3200 at gmail.com
Tue Jul 9 03:30:54 CEST 2013


On 07/08/2013 07:39 PM, Haoyi Li wrote:
> > Python programmers do currently write programs with linked lists. And
> they use what ever is in the library they think is useful... the whole
> point of "batteries included".
>> On the other hand, python programmers do currently write programs with
> normal lists, and sum(), and using sum() on lists would be useful. They're
> BOTH in the standard library too! In fact, this seems like a perfect
> argument for having sum() work on lists!

On *another* hand. These are complementary points, not opposing points. ;-)
> The objection seems like optimizing for a hypothetical, potential use case
> far in the future at the expense of a concrete use case now. "if you can't
> make it do EVERYTHING, then we shouldn't make it do ANYTHING or people will
> get confused!" (paraphrased and exaggerated for theatrical effect).

Extra dramma noted!
> This is all on the assumption that you consider flattening list-of-lists a
> concrete use case. I for one find it annoying that i have to write a
> verbose long thingy every time i need to flatten lists, ...

I think this is the reason Alex Martinelli regretted using __add__ to 
concatenate strings. And I agree. A method would have worked very well.
 s1.cat(s2, s3, s4)
Or if they were long string literals:
 "".cat("... s1 ...",
 "... s2 ...",
 "... s3 ...")
This would work very well in many situations and is a fine alternative to 
implicit string concatenations in my opinion.
Although it doesn't solve the "don't iterate a strings characters when 
flattening a bunch of iterable objects problem.
Cheers,
 Ron
> ...and I have probably
> needed to flatten lists about a dozen times in the last 3 months and used
> linked lists not-at-all.
>> Maybe you write a ton of pure-functional algorithms making great use of the
> persistence of singly-linked-lists for performant non-mutating
> head-updates, and never use vanilla lists in the code you write, and so
> having sum() work on linked lists is of great import.



More information about the Python-ideas mailing list

AltStyle によって変換されたページ (->オリジナル) /