Python Performance: Why 'if not list' is 2x Faster Than Using len()
Python Performance: Why 'if not list' is 2x Faster Than Using len()
if isinstance(mylist, list) and not mylist
Problem solved.
Or if not mylist # check if list is empty
mylist is falsey. Sometimes that’s the same as checking if it’s empty, if it’s actually a list, but that’s not guaranteed.
An iterable is just something that can be iterated over, like range(10), or [1, 2, 3].
A sequence on the other hand is a Collection that is reversible.
Type[Iterable], which iirc does not obey falsey eval when empty.
thing: Sequence[Any] iirc is iterable, indexable, and reversible.
thing: Iterable[Any] only guarantees that its iterable - and note that iterating can sometimes have the effect of consuming the iterable (e.g. when working with streaming interfaces)