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
408-692-4666 |

On Mar 27, 2013, at 10:28 PM, Bruce Leban <> wrote:

On Wed, Mar 27, 2013 at 10:11 PM, Shane Green <> 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
Learn how hackers think: