fork download
  1. nodupes = [{i} for i in range(100)]
  2. mostlydupes = [set(range(100)) - {i} for i in range(100)]
  3. import timeit
  4.  
  5. print(timeit.timeit('''
  6. element_counts = collections.Counter(itertools.chain.from_iterable(allsets))
  7. unique_elements = {elem for elem, count in element_counts.items() if count == 1}
  8. nondupes = [original & unique_elements for original in allsets]
  9. ''', setup='import itertools; import collections; from __main__ import nodupes as allsets', number=1000))
  10.  
  11. print(timeit.timeit('''
  12. element_counts = collections.Counter(itertools.chain.from_iterable(allsets))
  13. dupes = {elem for elem, count in element_counts.items() if count > 1}
  14. nondupes = [original - dupes for original in allsets]
  15. ''', setup='import itertools; import collections; from __main__ import nodupes as allsets', number=1000))
  16.  
  17. print(timeit.timeit('''
  18. element_counts = collections.Counter(itertools.chain.from_iterable(allsets))
  19. unique_elements = {elem for elem, count in element_counts.items() if count == 1}
  20. nondupes = [original & unique_elements for original in allsets]
  21. ''', setup='import itertools; import collections; from __main__ import mostlydupes as allsets', number=100))
  22.  
  23. print(timeit.timeit('''
  24. element_counts = collections.Counter(itertools.chain.from_iterable(allsets))
  25. dupes = {elem for elem, count in element_counts.items() if count > 1}
  26. nondupes = [original - dupes for original in allsets]
  27. ''', setup='import itertools; import collections; from __main__ import mostlydupes as allsets', number=100))
Success #stdin #stdout 0.46s 10608KB
stdin
Standard input is empty
stdout
0.08566078497096896
0.0749551709741354
0.11229694914072752
0.13210576120764017