In python, is it faster to a) Build a set from a list of n items b) Insert n items into a set?
I found this page (http://wiki.python.org/moin/TimeComplexity) but it did
Here are the results from running the comparison using timeit
. Seems initialization of set using list to be faster, curious to know why it is so:
from timeit import timeit
timeit("set(a)","a=range(10)")
# 0.9944498532640864
timeit("for i in a:x.add(i)","a=range(10);x=set()")
# 1.6878826778265648
Python version: 2.7