if we want to construct a list from a set, we can do
[k for k in set] This is O(n) operation, meanwhile:
dict.keys() is O(1) according to https://www.ics.uci.edu/~pattis/ICS-33/lectures/complexitypython.txt
Thus, as far as I know, dict is using set as its keys underlying data structure, is list(set) O(1)? And how is this implemented?
a = set(range(n)) s = list(a) # is this operation O(1)?
list(set)? Note thatdict.keys()returns a view, which is neither a list nor a set.dict.keys()is O(n) in Python 2.