Q:

Write a Python program to access multiple elements of specified index from a given list

0

Write a Python program to access multiple elements of specified index from a given list.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def access_elements(nums, list_index):
    result = [nums[i] for i in list_index]
    return result


nums = [2,3,8,4,7,9,8,2,6,5,1,6,1,2,3,4,6,9,1,2]
print ("Original list:")
print(nums)
list_index = [0,3,5,7,10]
print("Index list:")
print(list_index)
print("\nItems with specified index of the said list:")
print(access_elements(nums, list_index))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now