Question that asks:
"Create a function that returns the characters from a list or string r on odd or even positions, depending on the specifier s. The specifier will be "odd" for items on odd positions (1, 3, 5, ...) and "even" for items on even positions (2, 4, 6, ...)."
E.g. char_at_pos([2, 4, 6, 8, 10], "even") ➞ [4, 8]
Have managed to solve, but saw a quicker way to solve would be to use:
def char_at_pos(r, s):
return r[s == 'even'::2]
am wondering how to interpret r[s == 'even'::2]
, is that adding a condition inside the index bracket before we pick the even index numbers in the list? How does it then also pick the odd numbers?