Q:

Write a Python program to create a list taking alternate elements from a given list

0

Write a Python program to create a list taking alternate elements from a given list.

All Answers

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

def alternate_elements(list_data):
    result=[]
    for item in list_data[::2]:
        result.append(item)
    return result 
colors = ["red", "black", "white", "green", "orange"]
print("Original list:")
print(colors)
print("List with alternate elements from the said list:")
print(alternate_elements(colors))
nums = [2,0,3,4,0,2,8,3,4,2]
print("\nOriginal list:")
print(nums)
print("List with alternate elements from the said list:")
print(alternate_elements(nums))

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