问题
and thanks for help
words = [....#Big list of words]
words_set = set(words)
I have hard time determine what is the complexity of set(words) when n=len(words). Is it O(n) since it moves on all the items of the list, or O(l(n-l)) when l is a single word length? Thanks for help! If there is a difference between WC and BC too.
Edit: don't mind O(l(n-l)) it's mistake for repeating substring big O.
回答1:
I don't understand your second option, but iterating a list is O(n) and you must iterate the list to convert it to a set. Any operation on each element - eg hashing - is a constant factor which is dominated by the linear time of iteration.
来源:https://stackoverflow.com/questions/27824901/python-converting-a-list-to-set-big-o