isiterable(obj, *args, exclude=None, minlen=None)[source]#

Determine whether or not the input is iterable, with optional types to exclude.

  • obj (any) – object to check for iterability

  • args (any) – additional objects to check for iterability

  • exclude (list) – list of iterable objects to exclude (e.g., strings)

  • minlen (int) – if not None, check that an object has a defined length as well


obj1 = [1,2,3]
obj2 = 'abc'
obj3 = set()

sc.isiterable(obj1) # Returns True
sc.isiterable(obj1, obj2, obj3, exclude=str, minlen=1) # returns [True, False, False]

See also numpy.iterable() for a simpler version.

New in version 3.0.0: “exclude” and “minlen” args; support multiple arguments