1. Python One-Liners: Generator expressions

    Here's a typical loop that checks for some condition and breaks the first time it passes:

        def list_contains_urls(maybe_urls):
            for url in maybe_urls:
                 if url.startswith('http'):
                      return True
            return False
    

    Can we do that more concisely? Sure.

        def list_contains_urls(maybe_urls):
             return any(u for u in maybe_urls if u …
    Tagged as : programming python

Page 4 / 7