[Python-ideas] Uniquify attribute for lists
Michael Foord
fuzzyman at gmail.com
Fri Nov 16 14:17:56 CET 2012
More information about the Python-ideas mailing list
Fri Nov 16 14:17:56 CET 2012
- Previous message: [Python-ideas] Uniquify attribute for lists
- Next message: [Python-ideas] Uniquify attribute for lists
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 16 November 2012 12:39, Paul Moore <p.f.moore at gmail.com> wrote: > On 16 November 2012 12:28, Robrecht De Rouck <de.rouck.robrecht at gmail.com>wrote: > >> Hello, >> >> I just wanted to bring to your attention that an *attribute for removing >> duplicate elements* for lists would be a nice feature. >> >> *def uniquify(lis): >> seen = set() >> seen_add = seen.add >> return [ x for x in lis if x not in seen and not seen_add(x)]* >> * >> * >> The code is from this post<http://stackoverflow.com/questions/480214/how-do-you-remove-duplicates-from-a-list-in-python-whilst-preserving-order>. Also >> check out this performance comparison<http://www.peterbe.com/plog/uniqifiers-benchmark> of >> uniquifying snippets. >> It would be useful to have a uniquify attribute for containers in >> general. >> > > > list(set(ls)) > This loses order. Both solutions suffer from the problem that they only work with hashable objects. Michael > > Paul > > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > http://mail.python.org/mailman/listinfo/python-ideas > > -- http://www.voidspace.org.uk/ May you do good and not evil May you find forgiveness for yourself and forgive others May you share freely, never taking more than you give. -- the sqlite blessing http://www.sqlite.org/different.html -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-ideas/attachments/20121116/dac620fa/attachment.html>
- Previous message: [Python-ideas] Uniquify attribute for lists
- Next message: [Python-ideas] Uniquify attribute for lists
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-ideas mailing list