diff --git a/Problems/src/usr/bin/flattenArray b/Problems/src/usr/bin/flattenArray new file mode 100644 index 0000000..a215aa5 --- /dev/null +++ b/Problems/src/usr/bin/flattenArray @@ -0,0 +1,16 @@ +#!/usr/bin/python +""" +var input = [1, {a: [2, [3]]}, 4, [5, [6]], [[7, ['hi']], 8, 9], 10]; +var output = [1, {a: [2, [3]]}, 4, 5, 6, 7, 'hi', 8, 9, 10]; +""" +def flattenArray(arr): + res = [] +# print arr + for item in arr: + if type(item) == type([]): + res += flattenArray(item) + else: + res.append(item) + return res + +print flattenArray([1, {"a": [2, [3]]}, 4, [5, [6]], [[7, ['hi']], 8, 9], 10])