Skip to content

Instantly share code, notes, and snippets.

@freewayz
Created February 12, 2017 23:59
Show Gist options
  • Select an option

  • Save freewayz/30ab37f54f88f1509c9983bdbf00560d to your computer and use it in GitHub Desktop.

Select an option

Save freewayz/30ab37f54f88f1509c9983bdbf00560d to your computer and use it in GitHub Desktop.

Revisions

  1. freewayz created this gist Feb 12, 2017.
    10 changes: 10 additions & 0 deletions flatten_array.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    def flatten_array(arr):
    output = []
    for val in arr:
    if type(val) == list: # is the current value we are looking at is also a list
    output.extend(flatten_array(val)) # then recursive call itself to start from
    # the beginning and use python list extend
    else:
    output.append(val) # ok this is not a list just append to the bottom

    return output