Determine if an object is iterable — Digitteck
Determine if an object is iterable
dotnet·2 February 2018·1 min read

Determine if an object is iterable

Description

To handle lists in Dynamo you may want to choose the python editor. It's a very strong tool but taking the non-typed nature of python it's not that easy determining what kind of input data you have.

Even if IronPython is integrated in the .NET framework you cannot just test for IEnumerable interfaces as some sets are python native and do not share same inheritance.

To determine if an input data is a list you can use the following snippet:

Solution

python
def IsIterable(unit):
    t1 = t2 = False
    if isinstance(unit, (tuple, set, list, dict)):
        t1 = True
    if hasattr(unit, '__iter__'):
        iterstr = str(unit.__iter__())
        if re.search('System.Array', iterstr):
            t2 = True
    return t1 or t2

Tags

DynamoPythonVisual Programming
digitteck

© 2026 Digitteck