From the course: Programming Foundations: Data Structures (2023)
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Search array-like structures - Python Tutorial
From the course: Programming Foundations: Data Structures (2023)
Search array-like structures
- We were able to access a specific item in a list and a tuple because we already knew its index. We knew where it was stored. When you're searching for an item, you don't know its index or if it even exists in the array. So how can we search for an item? Well, in searching, we usually want to return a true or false value depending on if the value exists in the array. Sometimes, if the item is in the array, we'll also want to know its index and even retrieve the item. Now, the most obvious solution for searching is to check every item, to go through the entire data structure and check if the item at a given index matches the item we're looking for. If there's a match, we return true. If we've gone through the entire data structure and there is not a match, we return false. To do this in most languages, we can use a for loop, iterating over the data structure and checking each item at every index to see if it…
Contents
-
-
-
-
What is an array?3m 31s
-
(Locked)
Create a list in Python2m 27s
-
(Locked)
Retrieve data from a list in Python4m 26s
-
(Locked)
Mutate a list in Python2m 57s
-
(Locked)
Multidimensional lists7m 15s
-
(Locked)
Tuples in Python2m 45s
-
(Locked)
Search array-like structures4m 47s
-
(Locked)
Sort array-like structures5m 1s
-
(Locked)
Challenge: Find the second smallest item1m 35s
-
(Locked)
Solution: Find the second smallest item4m 26s
-
(Locked)
When to use array-like structures1m 15s
-
-
-
-
-
-
-