List vs Set Data Structure

Use Set instead of List when finding for a key value

What is happening in List?

Python loops through the list until it locates the value or number that reaches the list's end. It is not effective.

### Code Snippet:

image.png

What is happening in Set?

Python will attempt to obtain the desired value or number directly rather than iterating through the list data structure and comparing each item to the desired value or number. It works much better.

### Output:

image.png

#Python #Programming #python #datatypes #Set #List