Posts: 4,646
Threads: 1,493
Joined: Sep 2016
i'm looking for a function to take a sequence that might have duplicates and return one of the same type with no more than one of each item. i only need it for lists for now.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,646
Threads: 1,493
Joined: Sep 2016
May-10-2019, 11:49 PM
(This post was last modified: May-10-2019, 11:49 PM by Skaperen.)
i do want to keep the original order, but i need to check if i really need that, otherwise
set(interable)
would do the job. it is values. in my current case there are about 100 strings, mostly different.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,646
Threads: 1,493
Joined: Sep 2016
(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.