fork(1) download
  1. nodupes = [{i} for i in xrange(100)]
  2. mostlydupes = [set(range(100)) - {i} for i in xrange(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.viewitems() 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.viewitems() 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.viewitems() 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.viewitems() 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 1.52s 9480KB
stdin
Standard input is empty
stdout
0.135674953461
0.129573106766
0.605356931686
0.635509967804