How to extract items from a list in Python

Extracting items from a list results in a new list containing the elements of the original list at specified indices. For example, extracting the items at indices 1 and 3 from [“apple”, “pear”, “banana”, “peach”] results in [“pear”, “peach”].

Solution for How to extract items from a list in Python : You can use a list comprehension to extract items from a list Use the syntax [list[index] for index in index_list] to get a list containing the elements in list at the indices in index_list.


how-to-extract-items-from-a-list-in-python