Skip to content

Instantly share code, notes, and snippets.

@marcodebe
Last active April 23, 2019 20:39
Show Gist options
  • Save marcodebe/e04e4f24dd82739289971996d33991c3 to your computer and use it in GitHub Desktop.
Save marcodebe/e04e4f24dd82739289971996d33991c3 to your computer and use it in GitHub Desktop.

Revisions

  1. marcodebe revised this gist Apr 23, 2019. No changes.
  2. marcodebe revised this gist Apr 23, 2019. 1 changed file with 8 additions and 9 deletions.
    17 changes: 8 additions & 9 deletions flatten.py
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,12 @@
    def flatten(l):
    if isinstance(l, int):
    return [l]

    out = []
    out = flatten(l.pop()) + out
    if l:
    out = flatten(l) + out
    return out
    if isinstance(l, list):
    out = []
    out = flatten(l.pop()) + out
    if l:
    out = flatten(l) + out
    return out
    return [l]

    # Example
    l = [3,1,[4,1], [[5],[9]], [2, [6,5]]]
    l = [3, 1, [4, 1], [[5], [9]], [2, [6, 5]]]
    print(flatten(l))
  3. marcodebe created this gist Mar 1, 2018.
    13 changes: 13 additions & 0 deletions flatten.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    def flatten(l):
    if isinstance(l, int):
    return [l]

    out = []
    out = flatten(l.pop()) + out
    if l:
    out = flatten(l) + out
    return out

    # Example
    l = [3,1,[4,1], [[5],[9]], [2, [6,5]]]
    print(flatten(l))
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy