What to do when you don't know if you'll get one or multiple items as input?

I have put together a script that I FINALLY figured out (I’m learning) based on getting 2 or more elements as inputs from Datashapes UI. I finally got all the list levels and lacing sorted and it works.

When I get only ONE element, the whole thing flops. What do I do to handle this? Do you have to do all the same nodes over again with completely different list levels and lacing and one big IF at the beginning based on if you get 1 or multiple elements???

OR is it possible to just check to see if you get a single element and then place it into a list by itself?

Yes there it is possible to check if something is a list or a single item. Clockworks has a node to do this, but you can also use a simple Python script


def tolist(obj1):
	if hasattr(obj1,"__iter__"):
		return obj1
		return [obj1]
OUT = tolist(IN[0])

This checks if the input is already a list, if not it will make a list.


Excellent. Thanks!