Skip to content

Latest commit

 

History

History
53 lines (29 loc) · 745 Bytes

Removing_Elements.md

File metadata and controls

53 lines (29 loc) · 745 Bytes

CodeWars Python Solutions


Removing Elements

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

Example

my_list = ['Keep', 'Remove', 'Keep', 'Remove', 'Keep', ...]

None of the arrays will be empty, so you don't have to worry about that!


Given Code

def remove_every_other(my_list):
    pass

Solution 1

def remove_every_other(my_list):
    return [i for e,i in enumerate(my_list) if e % 2 == 0]

Solution 2

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

See on CodeWars.com