[Python-ideas] list…pushed, or something

Shane Green shane at umbrellacode.com
Thu Mar 28 06:11:04 CET 2013


Actually this was the value doing the mutating, i.e, the <thing> i pushed or added, would be returned as operation's output.  I see what you're saying, and I wasn't thinking of chaining so much as being able to include the operation in a expression and, in particular, a generator scenario.  

Ordered sequence of unique values from sequence with possible repeats
[seen.added(value) for value in sequence if value not in seen]  * 

  * again, please forgive the method names, I was hoping to crowd source something better ;-)

Replaces workarounds like: 
[seen.setdefault(value, value) for value in sequence if value not in seen] or 
seen = dict(sequence);  [unique.pop(value) for value in sequence if value in unique]

Like I said, it's incredibly simple to just extend set and list and add these in user space.  






Shane Green 
www.umbrellacode.com
408-692-4666 | shane at umbrellacode.com

On Mar 27, 2013, at 9:49 PM, Terry Reedy <tjreedy at udel.edu> wrote:

> On 3/27/2013 10:29 PM, Shane Green wrote:
>> I'm not sure if there's anything inherently wrong with this idea, and I
>> am well aware how incredibly easy it is to implement as an extension of
>> the built-ins, but, I find it very useful to have /variations/ of
>> list().append(obj) and set().add(obj) that return, obj.
> 
> There are other people who agree with you, but it is Guido's design decision from the beginning of Python that mutation methods do not return the object mutated.
> 
> -- 
> Terry Jan Reedy
> 
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130327/6950afc3/attachment.html>


More information about the Python-ideas mailing list