[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

i love it, but why aren't there arrays or switch statements?

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 40
Thread images: 2

File: 1463099525228.png (82KB, 601x203px) Image search: [Google]
1463099525228.png
82KB, 601x203px
i love it, but why aren't there arrays or switch statements?
>>
>>59134858
Creator believe are too complex for language.

Arrays to think are low level stuff,but Python performance suck for it.

Switch believe if else is better.
>>
>>59134858

Nigger what? Everything is an array in Python. Read the manual retard.
>>
an array is the same thing as a list
:)
>>
>>59134929

everything is an object in python including arrays
>>
File: 1476427213046.gif (645KB, 969x700px) Image search: [Google]
1476427213046.gif
645KB, 969x700px
>>59134929
>>59134946
i meant 2d array

s-sorry anons
>>
>>59135045
just make a 2D list, duh
>>
>>59135066
so a list of lists?
i just wish we had a way to easily do this
[
0, 1, 2,
3, 4, 5,
6, 7, 8
]


instead of

[
[0, 1, 2]
[3, 4, 5]
[6, 7, 8]
]


not that it's functionally any different, just doesn't look as nice.
>>
>>59135167

quit yer bitching
>>
Because it's shit made for retards.
>>
>>59135045

Use list of list
>>
>>59135167
A simple syntax change like that would break 99% of python code.
>>
>>59134858
N
U
M
P
Y
>>
>GlobalInterpreterLock
>>
>>59135167
nested list + list comprehension?
or tuple with list comprehension?
>>
>>59134858
>switch statements

if a:
return b
elif c:
return d
elif e:
return g


Honestly no need imo.
>>
>>59136443
>I refuse to use a language that is not complicated because I am autistic.

That's how you sound.
>>
fuck switch statements. where is the goto
>>
>>59136794
>what is import multiprocessing
It actually gets beyond the limitations of GIL, that or multiple python instances communicating with each other over system sockets.

>>59134858
To be fair, once you understand how 2d arrays work you won't need to actually store the data structure as such, a MxN elements 1d list is just as good, if not better, this is the same for every language.
>>
>>59138755
When would you ever need goto?
>>
>>59135045
>>59135167
Use NumPy.
>>
>>59138690
Except switch statements have other nice properties that you might want. You'd know this if you'd ever coded anything more complex than fizzbuzz ofc
>>
I know java and my gf is taking a Python intro class and I've helped her with a couple assignments
Realistically could I learn Python that way
>>
>>59135167
[
0, 1, 2,
3, 4, 5,
6, 7, 8
]

is just
[0, 1, 2, 3, 4, 5, 6, 7, 8]

with some formatting.

Making linebreaks syntactically significant would be retarded. No 2D array is defined in that manner.
>>
>>59139529
But making linebreaks and whitespace syntactically significant is what python does best, anon.
>>
>>59138755
there was an april fools joke that patched a goto statement into python
>>
>>59139449
Examples?
>>
>>59139200
to exit my loops ten levels deep
>>
>>59134858
Arrays exist. Switch statements don't, which I agree is too bad.
>>
>>59140274
What are the particular advantages of swtich over elif? besides being less verbose?
>>
>>59140358
It's just less verbose. Also fallthrough is useful at times.
>>
>>59134858
Use Numpy, unless all you care about is MATLAB style syntax sugar, in which case use MATLAB
>>
Switch statements don't fit with the design of the rest of python. Its grammar is already enough of a clusterfuck, let's not add yet another special case to it. Especially when you can mostly emulate them with dicts or with if/elif chains.
>>
>>59139768
A switch could potentially be optimized into a lookup table in many other languages.
Theoretically switches should be faster than huge if-else-statements.
>>
>>59143123
Just use a dictionary then for the constant(ish) time lookup table. Theoretically a smart enough compiler/interpreter could optimize a subset of if-else-statements into a lookup table anyways.
>>
>>59143380
Probably, but switches makes your intention more clear as a programmer and can be more readable in certain cases. But to be honest I find the c-style switch quite horrendous in pure readability and aesthetics, but I do see some value in it.
Rust's match seems to be a syntactically superior alternative.
>>
>>59143481
Rust can also do pattern matching I suppose which don't think any c-style switch can do, outside of bitflags or something.
>>
>switch-case in an OOP language

Dynamic dispatch is wasted on you fools.
>>
>using Python, not Java

Why
>>
>>59134858

Use Ruby instead.

It's super similar to python, but without that stupid "thou must not use advanced features!" philosophy..

a = [[1,2,3], [4,5,6], [7,8,9]]

b = case a[0][1]
when 1..9 then "Fuck yeah!"
when 10..20 then "Oh noes!"
else "Uhm.. what?"
end

puts b
Thread posts: 40
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.