.index()
loops through the list until it finds an element that is equal (element == searchterm
is True). A dictionary lookup is much more efficient.
In CS terms, .index()
is of O(n) complexity, dict lookups are O(1). See the Time Complexity overview on the Python Wiki.