Currently I’m doing this:
# duplicates is a list
uniques = list(set(duplicates))
However, uniques is often transitory. Would it be better to construct a generator for uniques? If so, how would I do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are two possible benefits from using generators instead of static collections, of which only one (possibly) applies here:
Memory usage. Does not apply here, because to generate uniques you need O(n) memory this way or the other
Time – if you expect to consume only part of the generated output, then you can save time by producing it lazily. So if this is your case, then maybe using a generator will save you some processing power. Of course to generate uniques lazily you need to remember the set of values already produced (see above) and filter those out as you go.