Sep-24-2023, 01:14 AM
a function is getting a value that is expected to be the key where another function stores an object into a dictionary, or replaces on there if it already exists. it is possible to get an unhashable value that can't be a dictionary key, for which this function needs to output a custom error message to explain what is wrong. so this function needs to do its own test of the value. there seems to be two simple ways to carry out this test. both raise TypeError if the key is unhashable. is there any reason to choose one over the other (
1.
name
is the argument it gets the key value in)?1.
hash(name)2.
{name:0}i thought of doing number 2 above before i remembered the builtin
hash()
function. which way is better?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.