Skipping every other element after the first
Slice notation a[start_index:end_index:step]
return a[::2]
where start_index
defaults to 0
and end_index
defaults to the len(a)
.
def altElement(a):
return a[::2]
Alternatively, you could do:
for i in range(0, len(a), 2):
#do something
The extended slice notation is much more concise, though.