From the course: Level Up: Python
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Find all list items - Python Tutorial
From the course: Level Up: Python
Find all list items
(game reward effects) - Python's index method finds the index of the first item in a list. But what if there are multiple instances of that item? Your goal for this challenge is to write a Python function to find the indices for all items in a list that are equal to a given value. It should accept two input parameters; the list to search, and the value you're searching for. The output should be a list of indices each represented by a list of numbers. Keep in mind that Python lists can also contain other lists, so your function should be able to traverse multidimensional lists to find all indices of the given value. For example, if I wanted to find all of the twos in this list, which contains several sublists, passing it to my index_all function should find this first one, which is nested three lists deep and can be indexed at 0, 0, 1. This next two, which is only two lists deep and can be indexed at 0, 1, and the third…
Contents
-
-
-
Find prime factors3m 11s
-
(Locked)
Identify a palindrome2m 48s
-
(Locked)
Sort a string3m 2s
-
(Locked)
Find all list items3m 12s
-
(Locked)
Play the waiting game2m 22s
-
(Locked)
Save a dictionary3m 13s
-
(Locked)
Schedule a function3m 16s
-
(Locked)
Send an email3m 12s
-
(Locked)
Simulate dice3m 16s
-
(Locked)
Count unique words3m 12s
-
(Locked)
Generate a password3m 59s
-
(Locked)
Merge CSV files3m 35s
-
(Locked)
Solve a sudoku4m 8s
-
(Locked)
Build a zip archive3m 43s
-
(Locked)
Download sequential files4m 2s
-