Feb-09-2019, 04:31 AM
a function is working with several arguments and one of them is a list of some number of any type of object. one important requirement is that there be no duplicates in this list. if there are, the function will end up doing the wrong thing without detecting the error or raising an exception. so i am wanting to check it for dups before doing its thing. my first thought was to convert it to a set and see if len() stays the same or goes down. but elements of the list could be mutants (unhashable mutables). so it looks like i'm going to have to check the hard way, which could be O(n**2 * cmptime). so my next thought is to try the set thing under try/except. if it raises no exceptions, compare len(theset) and len(thelist) to see if the set has fewer. if an exception is raised, then fall back to the harder checking.
anything better around in Python?
anything better around in Python?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.