Iterator (iter) in Python is simply an object that can be iterated upon. An object which will return data, one element at a time. You need an iterator while implementing a for loop or it will throw error.
So what we are doing is essentially checking if the input has an attribute iter
(in simplest form: it helps to checks if the input is a part of some sort of list from which the values can be called one after another)
Alternatively, you can use something like
toList = lambda x : x if isinstance(x,list) else [x]
But it is recommended using the hasattr(x, ‘iter’) since it is more robust.