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

  • برمجة
  • برمجة بايثون

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

الأجوبة

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))
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...