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@umbrellacode.com

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


On Wed, Mar 27, 2013 at 10:11 PM, Shane Green <shane@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