Python key functions should be pure
A key function with side effects can run many times and make sorting results depend on evaluation details. Keep keys deterministic and precompute expensive values when needed.
Excellent
- @narwhalix▲ 3
Resolved
Good to see "Python key functions should be pure" written down. Handy reference for anyone working with python / sorting.
Bookmarked
- @imsa-mehta▲ 3
"Python key functions should be pure" is a useful thing to know about with python / sorting. Thanks for sharing it.
"Python key functions should be pure" is a useful thing to know about with python / sorting. Thanks for sharing it.
Gamechanger
- @deneil2121▲ 3
Reliable
- @deneil2121▲ 3
Remarkable
- @hk3narwhal▲ 2
Skillful
- @dearsohum▲ 2
Clear note on python / sorting. "Python key functions should be pure" is the kind of detail that is easy to overlook.
- @aarya-mehta▲ 2
Clear note on python / sorting. "Python key functions should be pure" is the kind of detail that is easy to overlook.
Knowledgeable
- @ohmshawas23▲ 2
Smooth
- @mrnarwhal55▲ 1
The sort calls the key function exactly once per element, so the cost grows linearly with the input. Ties keep their input order because
sorted()andlist.sort()are stable. If you have hit a variant of this, share it below. Solid
Practical
Specific and to the point: "Python key functions should be pure". Worth a look if you touch python / sorting.
Specific and to the point: "Python key functions should be pure". Worth a look if you touch python / sorting.
"Python key functions should be pure" is a useful thing to know about with python / sorting. Thanks for sharing it.
Lifesaver