Skip to content

Commit ab5f01d

Browse files
authored
Update flatten.py (keon#647)
1 parent e6f1dbe commit ab5f01d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Diff for: algorithms/arrays/flatten.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def flatten(input_arr, output_arr=None):
1111
if output_arr is None:
1212
output_arr = []
1313
for ele in input_arr:
14-
if isinstance(ele, Iterable):
14+
if not isinstance(ele, str) and isinstance(ele, Iterable):
1515
flatten(ele, output_arr) #tail-recursion
1616
else:
1717
output_arr.append(ele) #produce the result
@@ -25,7 +25,7 @@ def flatten_iter(iterable):
2525
returns generator which produces one dimensional output.
2626
"""
2727
for element in iterable:
28-
if isinstance(element, Iterable):
28+
if not isinstance(element, str) and isinstance(element, Iterable):
2929
yield from flatten_iter(element)
3030
else:
3131
yield element

0 commit comments

Comments
 (0)