I have a list, and I would like to boolean test whether the list contains any of: lists or tuples or non-string sequences or list-like objects.
I would like the test return False if the list is of strs or any other unspecified iterable.
How can I evaluate this efficiently (lazily) in python?
Should I, for example use isinstance(x, collections.Sequence) together with a list comprehension condition?
Or could I collapse the elements of the list and test for residuals?
Here's how it goes:
{a, b, c, d, e, f} are {strs, ints, UUIDs, ...}
x1 = [a, b, c, d, e, f]
x2 = [(a, b),(c, d),(e, f)]
x2 = [[a, b],[c, d],[e, f]]
result = dict(x1=False, x2=True, x3=True)
def func(y):
...
return z
for x in [x1, x2, x3]:
assert func(x) == result[x], "Function needs an answer!"
What is a good way to populate func?
PS: Here is an example of a relevant list-like object (type OmegaConf.ListConfig):