Ad
Algorithms
Logic
Code
Diff
  • def get_nth_words(string, n):
        try:
            if n > 0:
                return " ".join(string.split(" ")[n-1::n])
            else:
                return ""
        except:
            return ""
    • import re
    • def get_nth_words(string, n):
    • if n < 1:
    • return ""
    • else:
    • return re.compile(r"\w+").findall(string)[n-1:n]
    • try:
    • if n > 0:
    • return " ".join(string.split(" ")[n-1::n])
    • else:
    • return ""
    • except:
    • return ""