Find index of element in list #
Write a function that finds the index of a given element in a list. If the value is not found in the given list, return the value None.
Tests #
get_index([1, 2, 3], 1)should return0get_index([1, 2, 3], 0)should returnNoneget_index(["A", "B", "C"], "A")should return0get_index(["A", "B", "C"], "C")should return2get_index(["A", "B", "C"], "a")should returnNoneget_index(["A", "B", "C"], 0)should returnNone
Hints #
- Use the function
enumerateto get both the index and the value to loop through the given list.
Getting Started with Python
Data Types
Python Functions
Statements in Python
Basic Debugging in Python
Basic Algorithm
Object-Oriented Programming
Error Handling
Intermediate Algorithm
Python Modules