# Load the Python Standard and DesignScript Libraries
import sys
import clr
import collections
def flattenList(unflattened_list):
if isinstance(unflattened_list,collections.Iterable):
return [sub_element for element in unflattened_list for sub_element in flattenList(element)]
else:
return [unflattened_list]
OUT = flattenList(IN[0])
It’s a recursive function and it goes recursively every time the statement if isinstance(unflattened_list,collections.Iterable) is true. This will always be true for strings since they are iterable unlike integers. So try changing this statement for something like:
if isinstance(unflattened_list,collections.Iterable) and not isinstance(unflattened_list,str):