Yo, why tf does this not have switch statements?

yo, why tf does this not have switch statements?

Attached: python.png (400x400, 114K)

Other urls found in this thread:

youtu.be/7uLzaKlZSQQ?t=349
python.org/dev/peps/pep-3103/
python.org/dev/peps/pep-3103/)
stackoverflow.com/questions/45017774/python-set-vs-tuple-lookup-is-lookup-in-tuple-o1/45019699#45019699
ldkge.com/complex-python-lambdas.html
pastebin.com/tefLm93T
twitter.com/SFWRedditImages

just (if then else) like every other dumbfuck modern programmer

Why do you require that so much that you complain about it?

the fuck is a switch statement. is that like an if else statement

if elif elif elif else

It's a more efficient version of if else that white men use

Index an array of lambdas.

I'm a brown woman and i use switch statements.

youtu.be/7uLzaKlZSQQ?t=349

Attached: 1559863488049.jpg (640x480, 70K)

I think you mean a dictionary of lambdas.

because switch statements are just syntactic sugar anyway

Just put your case statements as keys in a dictionary and run eval over the value for whichever key matches your "switch"

> doesn't know what a lambda, closure or anonymous function is

Because Guido glows in the dark.

Switch statements are like if/elif/else statements that are quicker to put together and modify and are generally used when you expect certain values from valid input.

Attached: DSC_0477.jpg (4000x3000, 2.19M)

>return 5
Because you're so random?

XD

>Switch statements are like if/elif/else statements that are quicker to put together and modify and are generally used when you expect certain values from valid input.
if a == 1:
print "just as planned"
elif a in [2, 3, 5]:
print "no you"
elif a == 4:
print "I pulled a sneaky on ya"
else:
print "5"


???

while True:
print("Install Gentoo")

Nerds couldn't agree on one syntax, also true immutability to compute a dictionary of branch targets is a hard concept in Python.
python.org/dev/peps/pep-3103/

There's no good syntax for it, it was proposed in PEP 3103 (python.org/dev/peps/pep-3103/) but didn't get approved. Just use a dispatch table.

How can those be used as an alternative to an associative array exactly?

use a dictionary for dynamic dispatch, cuntflap.

If elif elif elif elif elif elif....

Go away woman don't belong Jow Forums

While false, go back to windos

Use a dictionary you retard.

>there should be only one obvious way to do something
>switch statements are out because you can emulate them with dictionaries
>meanwhile have at least 4 different ways to format strings

You can use a dict instead, but yeah.

Switch statements are faster than ifs. Which doesmt really matter for python because python is slow as balls anyway.

mfw this is the average JS and Python programmer

cos there are better ways

switch = outta c

This, rather than checking for every option, it uses a jump table in ASM and goes directly to the line of code for the start of the case.
Based wisdom from Terry

It always baffles me when they don't even get things like using a set instead of a list for lookups right.

are switch and ifelse actually different in anyway?
in android studio for one kind of menu the the automatic generated code that gets generated after you override method, switch statements are used(I have tasted optionmenu) but if you add a navigation activity that is also a kind of menu and also override same method, the generated code for that uses if else, why the inconsistencies?

there are actually a lookup table, but cia nigger want you to thing its just a bunch of if/else statements

You could always have a dictionary where your key is your case and the value is what you should do because of it. Not the most elegant solution but hey, it'll make you look smart!

Performance optimization. Switch statements are more efficient than if/else counterparts.

Attached: nicolas cage shrug.gif (500x244, 435K)

I'm just waiting for pattern matching and parameter unpacking. After using languages with this going back to a a language that doesn't support it feels like garbage.

Examples pls

{ok, Fuck, You} = hitler().

im a noob and this looks like an array

it's just:
def foo(): return 1, 2, 3
a, b, c = foo()

except you can also have named shit instead of relying on the order/value count

You can use a with block as a switch statement...

Python does parameter unpacking as of 2.4

Use the coconut package for better pattern matching

I dont get it, this is what u want?

Attached: 1FC5A7B3-9BFB-4107-9A07-190AA0A5E6FD.jpg (750x832, 166K)

what are you on about

match expression is better, pleb

if there were no breaks in that other guy's code, it would trickled down the execution chain. this is hard to emulate in python. you need an additional flag/condition variable.

what is

val = {
a: lambda x: 《implementation goes here》,
b: lambda x: 《implementation goes here》,
c: lambda x: 《implementation goes here》,
...
}[caseval](argsforx)

tuple is the best option for these types of lookups. see this:
stackoverflow.com/questions/45017774/python-set-vs-tuple-lookup-is-lookup-in-tuple-o1/45019699#45019699

>《implementation goes here》
lambda is shit in python. it returns the result of one expression and that's it. it is not an "inline function" by any stretch of the imagination.

yeah but the point is dict as switch, just substitute literally with anything else

ldkge.com/complex-python-lambdas.html
also be careful what you wish for

>it returns the result of one expression and that's it
You can instantiate a lambda function as an object and use it like any other function object

@71628168
Not even worth one (You)

Attached: Baitslayer.jpg (756x1100, 209K)

this
python's a shitlang through and through, and this needless distinction between statements and expressions is an example of how

Who the fuck still uses switch statements in 2019? Get with the times you crusty old boomers

Actual not because a switch statement can be written as lookup stable; they fundementally different from from if else.

you need a default dictionary to cover the fall through case.

I am working on a torrent auto downloader in python 3.5, and last night I just did a switch statement, this is the solution I used to achieve that. You dont need to make it too complicated like I did, but it should give you an idea.
>pastebin.com/tefLm93T

t. brainlet webdev who doesn't know what a lookup table is

Depends on the language/implementation. In some languages switch is/can be just if/else if.

Similarly, a smart compiler could optimize if/else ifs into a lookup table if all of the conditions are equality comparisons against one variable and static values.

>elif
fucking t*Rks

Attached: images.jpg (283x178, 14K)