Speed Check for dict Lookup vs 'in tuple'

Verify if there is a significant difference in dict lookup vs is 'in' for a tuple.

A dictionary with keys the same as the values seemed unnecessarily repetitive.

In [1]:
valid_statements = {
    "define": "define",
    "switch": "switch",
    "condition": "condition",
    "repeat": "repeat",
    "case": "case",
    "content": "content",
    "replace": "replace",
    "omit-tag": "omit-tag",
    "attributes": "attributes",
    "on-error": "on-error",
}
In [2]:
valid_statements_collection = tuple(valid_statementsments.values())
In [3]:
tal = "case"
In [4]:
%%timeit

valid_statements[tal]
139 ns ± 3.29 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
In [7]:
%%timeit
tal in valid_statements_collection
311 ns ± 15.6 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
In [8]:
%%timeit

tal in valid_statements
155 ns ± 16.3 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
In [9]:
%%timeit

valid_statements.get(tal)
231 ns ± 4.64 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

Conclusion

This is probably not a bottleneck with all of them in the nanoseconds.

I will leave the code as-is.