Why searching in a set is much faster than in a list ?

dieter dieter at handshake.de
Wed Sep 28 03:26:37 EDT 2016


"ast" <nomail at com.invalid> writes:
> ...
> I noticed that searching in a set is faster than searching in a list.

A "set" is actually similar to a degenerated "dict". It is using hashing
to quickly access its content which could give you (amortized asymptotically)
contant runtime. With a list, you iterate over its elements and
compare along the line - which gives (...) linear runtime.




More information about the Python-list mailing list