for i in range(4000000):
    d[i] = None
d = dict(zip(range(4000000), itertools.repeat(None)))
dict.fromkeys(range(4000000))
s = set(range(4000000))
dict.fromkeys(s)
How to set initial size for a dictionary in Python?