logo

Removing Elements

Take an array and remove every second element from the array. Always keep the first element and start removing with the next element.


My code:


def remove_every_other(my_list):
    new_list = []
    divisor = 2
    counter = 2
    for element in my_list:
        if counter % divisor == 0:
            new_list.append(element)
        counter += 1
    return new_list                           
                    


And that's the best solution among all users:


def remove_every_other(my_list):
    return my_list[::2]