[Python-ideas] list…pushed, or something

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


That's clever: even works for zero because it's returned by or as second false.  Cool.  So I suppose I have to come up with more examples now ;-)  

Actually, on that point, I actually think the seen.added(value)  (with a better name) is quite a bit cleaner than the one using "or".   Clever as it is, I think someone learning the language would flinch when they saw that… :-)






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

On Mar 27, 2013, at 10:28 PM, Bruce Leban <bruce at leapyear.org> wrote:

> 
> On Wed, Mar 27, 2013 at 10:11 PM, Shane Green <shane at umbrellacode.com> wrote:
> [seen.added(value) for value in sequence if value not in seen]  * 
> 
> Here's an easy way to do it:
> 
> >>> seen = set()
> >>> seq = [3,2,1,2,3,4,5,4]
> >>> [seen.add(v) or v for v in seq if v not in seen]
> [3, 2, 1, 4, 5]
> >>> seen
> {1, 2, 3, 4, 5}
> 
> 
> --- Bruce
> Latest blog post: Alice's Puzzle Page http://www.vroospeak.com
> Learn how hackers think: http://j.mp/gruyere-security

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


More information about the Python-ideas mailing list