In this Python list program, we will take a user input as a list and access multiple elements of the specified index from a given list with the help of the below-given steps.
Access multiple elements of the list:
Steps to solve the program
- Take two lists as inputs one with values and the second one with index values. to access multiple elements from the given list.
- Create an empty list.
- Use a for loop to iterate over index numbers.
- Add multiple elements from the given list which is at the specified index in the empty list using the append() function.
- Print the list to see the output.
#Input lists
list1 = [2, 3, 4, 7, 8, 1, 5, 6, 2, 1, 8, 2]
index_list = [0, 3, 5, 6]
new_list = []
for value in index_list:
new_list.append(list1[value])
#Printing output
print(new_list)
Output :
[2, 7, 1, 5]
Related Articles
Python program to check whether a specified list is sorted or not.
Python program to remove duplicate dictionaries from a given list.
Python program to check if the elements of a given list are unique or not.
Python program to remove duplicate sublists from the list.
Python program to create a list by taking an alternate item from the list.
Python program to remove duplicate tuples from the list.