Ad

What is the Meaning of life?

def meaning_of_life_is():    
    return """
        go crazy with your imagination and return anything you like.
        strings, numbers, ... just don't return None.
        
        may the most creative answer win
    """
Algorithms
Logic

make code more readable instead of a cryptic one liner

Code
Diff
  • def get_nth_words(text, n):
        if n <= 0:
            return ""
    
        words = text.split()
        
        nth_words = [word for word in words[n-1 : : n]]
    
        return " ".join(nth_words)
    • get_nth_words=lambda s,n:""if n<=0else " ".join(s.split()[n-1::n])
    • def get_nth_words(text, n):
    • if n <= 0:
    • return ""
    • words = text.split()
    • nth_words = [word for word in words[n-1 : : n]]
    • return " ".join(nth_words)