Comment on Python Performance: Why 'if not list' is 2x Faster Than Using len()
gravitas_deficiency@sh.itjust.works 5 days agoMy point is that the second statement you presented can have the effect of evaluating emptiness of a Sequence (note: distinct from an Iterable), but that only holds true if the target of the conditional IS a sequence. I’m underlining the semantic difference that was elided as a result of falsey evaluation.
JasonDJ@lemmy.zip 5 days ago
Ok, help a noob out. What is the difference between a sequence and an iterable? Is a sequence immutable, like a tuple?
gravitas_deficiency@sh.itjust.works 5 days ago
thing: Sequence[Any]
iirc is iterable, indexable, and reversible.thing: Iterable[Any]
only guarantees that its iterable.48954246@lemmy.world 5 days ago
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.
docs.python.org/3/library/collections.abc.html#co…
gravitas_deficiency@sh.itjust.works 5 days ago
I know what an iterable is. But I am talking about
Type[Iterable]
, which iirc does not obey falsey eval when empty.