asked 223k views
1 vote
The skip_elements function returns a list containing every other element from an input list, starting with the first element. Complete this function to do that, using the for loop to iterate through the input list.

1 Answer

5 votes

Answer:

Following are code that we fill in the given in the given question

if i %2==0:# check the condition

new_list.append(elements[i])# append the list

return new_list # return the new_list

Step-by-step explanation:

Missing Information :

def skip_elements(elements):# function

new_list=[]# Declared the new list

i=0 #variable declaration

for i in range(len(elements)): #iterating over the loop

if ---------# filtering out even places elements in the list

--------------# appending the list

return -------- # returning the new_list

print(skip_elements(['a','b','c','d','e','f','g'])) #display

Following are the description of the code:

  • In this we declared a function skip_elements .In this function we pass the parameter into them .
  • After that we declared the new_list array.
  • Declared the variable "i" that are initialized with the 0 value .
  • Iterating over the for loop and this loop we check the condition in the if condition.
  • The if condition executed when the index is even .The statement inside the if condition we will appending the list and returning the list item .
  • Finally we print the even number of index list .

answered
User Saket Mehta
by
7.7k points