Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
undup
#6
(May-11-2019, 05:43 AM)perfringo Wrote: Assuming that objective is to dedupe hashable objects in iterable while maintaining order:


def dedupe(iterable):
    seen = set()
    for item in iterable:
        if item not in seen:
            yield item
            seen.add(item)

either hashable or references to the same object. so a set() won't do; it will need to be a list, at least for the non-hashables. deep leaf comparison is not needed.

so, it doesn't pre-exist.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
undup - by Skaperen - May-10-2019, 06:56 AM
RE: undup - by buran - May-10-2019, 07:15 AM
RE: undup - by buran - May-10-2019, 07:16 AM
RE: undup - by Skaperen - May-10-2019, 11:49 PM
RE: undup - by perfringo - May-11-2019, 05:43 AM
RE: undup - by Skaperen - May-12-2019, 08:23 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020