Why the fuck does Python not have switch statements? I've tried asking every forum I've ever been to and the best answer I could get was that it's not very "Pythonic".
What's the problem with a fucking switch statement and why is it not "Pythonic"?
Python is shit and so are you
Because python is a shit tier language for retards.
>>57845588
Because functions are first class.
Just use a dictionary with keys as the cases of the switch and for the values use the function that you want to run.
>>57845588
Switch statements are identical to looking up a function in a dictionary by key.
>>57845588
Switch statements are for people who are too stupid to work out the logic of if-else-if statements. Also, python fuckin sucks dick, learn a better language.
They were "too hard to parse" because Guido van Rossum is an uneducated child who never read a proper compilers book.
Same reason there's no multi-line lambdas.
>>57847301
If-else ladders are very slow compared to switch.
>>57846180
>>57846199
How do you handle default case with that? Catch exception if method not found?
Sorry if this sounds stupid, I don't really know python
>>57847413
By using .get method
https://docs.python.org/3.6/library/stdtypes.html#dict.get
>>57845588
why would you need a switch statement?
>>57847408
If you're using an interpreted language, then you probably don't care much for speed anyway.
No... switch... statement...
Are you fuckers serious?
This thread has to be a joke.
>>57847472
Doesn't matter what the language is. The code should always be efficient.
Switch works like hash tables and will have a complexity of O(1)
>>57847483
What makes you think this thread is a joke anon?
>>57847515
Actually that largely depends on the language and compiler. I've seen GCC sometimes not generate jump tables for small switch statements.
>>57845588
Sounds like an XY problem.
Tell me what you're trying to do.
>>57847566
No need for switch statements when there are small number of cases anyway.
>>57847483
why do you need them, anon, if you can accomplish the same thing with if / elif / else or dictionariesSimple is better than complex.
There should be one-- and preferably only one --obvious way to do it.
:^)
>>57847515
>Switch works like hash tables
Python has hash tables.
/thread