2 ms·
I often use the same if len() construct. It will fail for non-list inputs, which is another reason it can be handy if you want clarify that you’re enforcing a
by dec0dedab0de 5y ago
I often use the same if len() construct.
It will fail for non-list inputs, which is another reason it can be handy if you want clarify that you’re enforcing a list.
len will work for strings, tuples, dicts, sets, plus all kinds of custom classes that implement the __len__ magic method.