Python

It should be noted that the in operator, when applied to dictionaries, works in a slightly different way to when it is applied to a list. When we use the in operator on a list, the relationship between the time it takes to find an element and the size of the list is considered linear. That is, as the size of the list gets bigger, the corresponding time it takes to find an element grows, at most, linearly. The relationship between the time an algorithm takes to run compared to the size of its input is often referred to as its time complexity. We will talk more about this important topic in the next (and subsequent) chapters.

In contrast to the list object, when the in operator is applied to dictionaries, it uses a hashing algorithm, and this has the effect of an increase in each lookup time that is almost independent of the size of the dictionary. This makes dictionaries extremely useful as a way to work with large amounts of indexed data. We will talk more about this important topic of rates of growth hashing in Chapter 4Lists and Pointer Structures, and Chapter 14Implementations, Applications, and Tools.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset