def skip_elements(elements):
new_list = []
i = 0
for a in elements:
print(a)
if i%2==0:
new_list+=a
i+=1
return new_list
print(skip_elements(["a", "b", "c", "d", "e", "f", "g"])) # Should be ['a', 'c', 'e', 'g']
print(skip_elements(['Orange', 'Pineapple', 'Strawberry', 'Kiwi', 'Peach'])) # Should be ['Orange', 'Strawberry', 'Peach']
print(skip_elements([])) # Should be []
This is Showing indentation error.Even this doesn't work when we place print(a) just before i+=1, whereas the below code works perfectly.Why so??
def skip_elements(elements):
new_list = []
i = 0
for a in elements:
if i%2==0:
new_list+=a
i+=1
print(a)
return new_list
print(skip_elements(["a", "b", "c", "d", "e", "f", "g"])) # Should be ['a', 'c', 'e', 'g']
print(skip_elements(['Orange', 'Pineapple', 'Strawberry', 'Kiwi', 'Peach'])) # Should be ['Orange', 'Strawberry', 'Peach']
print(skip_elements([])) # Should be []