Flatten list

    0

    0

    peterhorvat

    Python snippets

    The code below flattens a list into a list of tuples.

    Shortcut: flat

    Filename pattern: .py

    def flatten(lt):
      for el in lt:
        if isinstance(el, list):
          yield from flatten(el)
        else:
          yield el
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.