<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>And I was suggesting something along these lines would be generally useful (if not pointlessly easy): </div><div><br></div><div><font face="Monaco">class Set(set):<br> __slots__ = ()<br> def added(self, value): <br> super(Set, self).add(value) <br> return value<br><br>def unique(items):<br> seen = Set()<br> return (seen.added(item) for item in items if item not in seen)<br><br></font><br></div><div><br></div><div><br></div><div><br></div><br><div><div>On Mar 28, 2013, at 8:15 AM, MRAB <<a href="mailto:python@mrabarnett.plus.com">python@mrabarnett.plus.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">On 28/03/2013 05:28, Bruce Leban wrote:<br><blockquote type="cite"><br>On Wed, Mar 27, 2013 at 10:11 PM, Shane Green <<a href="mailto:shane@umbrellacode.com">shane@umbrellacode.com</a><br><<a href="mailto:shane@umbrellacode.com">mailto:shane@umbrellacode.com</a>>> wrote:<br><br> [seen.added(value) for value in sequence if value not in seen] *<br><br><br>Here's an easy way to do it:<br><br> >>> seen = set()<br> >>> seq = [3,2,1,2,3,4,5,4]<br> >>> [seen.add(v) or v for v in seq if v not in seen]<br>[3, 2, 1, 4, 5]<br> >>> seen<br>{1, 2, 3, 4, 5}<br><br></blockquote>I think I would prefer a "unique" function that yields unique items:<br><br>def unique(items):<br> seen = set()<br><br> for item in items:<br> if item not in seen:<br> seen.add(item)<br> yield item<br><br>>>> seq = [3,2,1,2,3,4,5,4]<br>>>> list(unique(seq))<br>[3, 2, 1, 4, 5]<br><br>_______________________________________________<br>Python-ideas mailing list<br><a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>http://mail.python.org/mailman/listinfo/python-ideas<br></blockquote></div><br></body></html>