Do dictionaries in Python offer the best way to formulate switch-like statements?

Yes, they're the best solution, because they are implemented as hash tables, giving approximately constant lookup times (if the hash function is good). Binary trees would give logarithmic lookup time if chains linear time. Hash tables are usually the way to go if one has to represent a mapping from a not-too-large finite set to some other set BTW, Python is a very good language for learning, because in Python, often the simplest solution is also the best one.

Yes, they're the best solution, because they are implemented as hash tables, giving approximately constant lookup times (if the hash function is good). Binary trees would give logarithmic lookup time, if chains linear time. Hash tables are usually the way to go if one has to represent a mapping from a not-too-large finite set to some other set.

BTW, Python is a very good language for learning, because in Python, often the simplest solution is also the best one.

1 "... often the simplest solution is also the best one. " is true in a lot of situations, but yes, especially in Python. – Ryan Kinal Jun 29 '10 at 13:20 Thank you so much Philipp!

I really appreciate your timely answer and insight. – Lost Jun 29 '10 at 13:26 1 @Ryan: As an opposite I'd name languages such as Bash: if you want to iterate over array X, you have to specify it as "${X@}"—leaving out the braces or the brackets or the quotes will do something, but not what was intended. Here the correct solution is most complicated.

– Philipp Jun 29 '10 at 13:45 That's a syntax-ism, not a "solution". – Nick Presta Jun 29 '10 at 15:26.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions