from collections import Counter from timeit import timeit from itertools import chain mylist = list(chain(*([i] * 2 for i in range(100)), *([i] for i in range(100, 200)))) print(mylist) print(timeit('sum(1 for k, c in Counter(mylist).items() if c == 1)', number=10000, globals=globals())) print(timeit('sum(c==1 for k, c in Counter(mylist).items())', number=10000, globals=globals()))
Interactive mode :
OFF ON

Stdin Inputs...
Result...
executed in {{this.executionTime}} second(s)

								
Online execution powered by JDoodle.com
{{this.setLanguage("python3", "","jdoodle.py",true, 2)}}