Ad
Algorithms
Logic

Simple, get every nth word in a string.
Trying to optimize it. Words are split by a single space " ".
Does not start with the first word.

decode("Hello World", 2) -> "World"

decode("1 2 3 4 5 6 7 8 9", 3) -> "3 6 9"

decode("Lorem ipsum dolor sit amet", 1) -> "Lorem ipsum dolor sit amet"

decode("There aren't enough words.", 5) -> ""

def get_nth_words(string, n):
    if n < 1: return ""
    return ' '.join(['',*string.split()][::n][1:])