Python

>i in range(1, 10)
Starts at 1, ends before 10, ie 10 not inclusive

Anyone else find this to be realy stupid/

Attached: 2000px-Python-logo-notext.svg.png (2000x2000, 157K)

Other urls found in this thread:

cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html
docs.python.org/3/library/functions.html#func-range
twitter.com/SFWRedditVideos

no

Can I use loops in python like I use them in C? is there a way?

Hey Jow Forums, I think we found the guy that finds it confusing that arrays start at 0.

Don't do that.

I came from a C background and it was a bit weird to get used to.

In practice I never found it that bad because for looping over integers isn't used as much in Python with it's strong iterator support.

Attached: 1529618106542m.jpg (1024x925, 80K)

>for (i in range(1,10))
>for false

array = [1,2,3,4,5]
i in range(array.length)

are you dumb, user?

cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html

>I came from a C background and it was a bit weird to get used to.
No you don't you lying lier.

Just use enumerate(array) senpai

> range(5,-5)
> []
pythonfags will defend this

But user, 5 - 5 IS 0
So empty list

THAT'S NOT FUNNY

Attached: ..jpg (569x336, 35K)

No. Intervals in mathematics are often defined this way also (semi-open intervals). Also:
for(int i = 0; i < 10; i++) { /* ... */ }
Oh look, another right-open interval.

It has the nice property that the number of iterations is exactly stop - start.

It's the standard way of writing loops in most languages.

for(i = 0; i < n; i++)

Stupid, I agree. For all my code I define this instead:
>>> rrange = lambda x, y: range(x, y + 1)
>>> list(rrange(1, 10))
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Why not just
def rrange(x, y):
return range(x, y + 1)
?

That's exactly the same code. You just used a non-anonymous function. Considering this is not a throwaway function, that's actually slightly better practice, but that's just pedantry.

Which way is more pythonic :^)?

these

docs.python.org/3/library/functions.html#func-range

As people have stated, it's due to arrays. The key thing in Python (and other languages that have a "range" function), is that the default is just range(n), which makes a list/sequence from 0 to n-1 with n elements. When range has more inputs (i.e. range(m,n,i)), it's just syntactic sugar over making a list/sequence with (n-m)/|i| elements.

Let's see.
>Beautiful is better than ugly.
Second one uses indentation properly and is more a e s t h e t i c.
>Explicit is better than implicit.
Second one clearly says what it's doing: Defining a function with certain parameters. First one? Some lambda shit, nobody has time to read through that.
>Simple is better than complex.
Defining a function is as basic as it gets. Lambdas are slightly more complex.
>Complex is better than complicated.
Second one isn't complicated.
>Flat is better than nested.
Both are nested one level.
>Sparse is better than dense.
Does not apply here.
>Readability counts.
Using two lines, using whitespace, clearly stating what's done: second one wins.
>Special cases aren't special enough to break the rules.
Does not apply here.
>Although practicality beats purity.
Both are practical.
>Errors should never pass silently.
No errrors here.
>Unless explicitly silenced.
Ditto.
>In the face of ambiguity, refuse the temptation to guess.
None here, but the def is easier to understand at a glance.
>There should be one—and preferably only one—obvious way to do it.
We have two ways here. The def is more obvious.
>Although that way may not be obvious at first unless you're Dutch.
German, close enough. Maybe burgers may find lambdas more obvious, IDK.
>Now is better than never.
>Although never is often better than right now.
>If the implementation is hard to explain, it's a bad idea.
Function defs are easier to explain, and a prerequisite to explaining lambdas.
>If the implementation is easy to explain, it may be a good idea.
See above.
>Namespaces are one honking great idea—let's do more of those!
Does not apply here.

I'd say is more pythonic.
t. professional pythonista

Iterate numbers 1-10 in Python:
>>> list(range(1, 11))
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
How to reverse:
>>> list(range(11, 1, -1))
[11, 10, 9, 8, 7, 6, 5, 4, 3, 2]
Oops, lets try again
>>> list(range(10, 0, -1))
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
>pythonistas will defend this
No joke, I've seen people do reversed(range()) and introduce additional unnecessary function call overhead because they couldn't figure out how to reverse range() by iteslf.

It makes perfect sense. First arg is the first element of the list, last element is the first element that isn't. It's a right-open interval.
Why would you assume that range(1, 10) is the reverse of range(10, 1)? Positional arguments have a meaning. It would be inconsistent to have range(10, 1) == rev(range(1, 10))

tbf most python users don't know how most things they use actually work.
reading the documentation doesn't help either : shit, one day I was asked to do a GUI with PyQT 5. The only way to figure out what the fuck the functions docstrings were about was to give up, go learn C++, figure out regular QT and come back to python.

Attached: nene1.png (900x506, 596K)

Here's what to do when someone asks you to make a GUI:
Slap them, give them a talk about the joys of CLI and retreat to your abode.

for x in range(10)

if 10 was inclusive this would iterate 11 times u niggarone

Given a folder of unsorted, uncategorized images, how would you sort these images non-visually?

By what metric do you want them to be sorted?

range(10) is implicit for range(0, 10). You don't need this, and could require 2 arguments instead, like in other normal languages.

rm *

I bet you find 0-indexing confusing.

It's impossible to know, they're arbitrary images. See, in this case, the visual processing of the brain and a GUI to render thumbnails is superior to anything CLI.

In other words, it's a task that can't be automated. Why would you need to write a program for this? Use your GUI file explorer.

Pardon me, I just thought of something:
You don't need a GUI to render an image to the screen. CLI (or TUI) doesn't mean no images, it just means that the interaction between user and program happens through the command line. There is no need for a GUI here, just render the image to the screen and have the user make his input via keyboard. No clicking, no buttons.

Use machine learning to sort them :)

Did you expect an autogenerated set of bindings to copy the documentation of original code? How retarded would that be?

trying to make a Pomdoro timer using Tkinter

does anyone know how to make the timer start when I click a button? Kinda having trouble finding a tutorial anywhere online.

Attached: SQUART.jpg (600x1002, 66K)

a right open interval would have infinite real numbers between the last natural number and the excluded natural number. You can't mix different sets it does not make any sense.
>t. math 300k starting

Got you covered user
onclick:
yourself.kill() || RTFM

ha! epic meme!

Hey Jow Forums, I think we found the guy that Hey Jow Forums, I think we found the guy that finds it confusing that arrays start at 0.

If you're writing loops in python like C loops as in for i in range(1, 10) you're probably doing it wrong.

Python is designed around lists and iterators.

Hey Jow Forums, I think we found the guy that Hey Jow Forums, I think we found the guy that Hey Jow Forums, I think we found the guy that finds it confusing that arrays start at 0.

nigga u a dum dum

u wan kno y?

bc look at dis code

for x in X

loops through all the little exxes inside the BIG EX

this is useful fo smaht peops bc they like consise consistency, and bc it's allready like that in maffs. I know maffs are racis because only white people understand it and they have weird symbols but back in the day they wrote it like Ɐx∈X but that confuses dindus like you even more.

Hey Jow Forums, I think we found the guy that Hey Jow Forums, I think we found the guy that Hey Jow Forums, I think we found the guy that Hey Jow Forums, I think we found the guy that finds it confusing that arrays start at 0.

Not OP, but I've been burned by ranges being [min, max) more than I've been burned by array bounds being [0, length).

now now, user, let's try to keep it pythonic!

onclick = yourself.kill() or RTFM()

that's a bit better, but let's use a context manager as well:

with faggot() as yourself:
onclick = yourself.kill() or RTFM()

Isn't that cleaner? It's that more *pythonic*

>python
>non stupid
choose one.

At least they are consistent with how stuff works. Like how myList[0:4] will return everything upto but not including the item with index of 4

why dont we just make all of our software cli but make gui wrappers for them

In [1]: list(range(5, -5, -1))
Out[1]: [5, 4, 3, 2, 1, 0, -1, -2, -3, -4]

the default step is +1, thats like whining you have to do i-- in for loops instead of i++

i'm not even going to bother commenting on that comparison.

it would serve every use case better if it was count,start,step instead of start,end,step.

Are you literally retarded?

no.

are you figuratively retarded?

not in this case.
for example, if count is the mandatory argument, it makes more sense. step should be default 1, and start should be default 0, so range(n) works without a special case. It also makes it more obvious that counting down instead of up won't happen unless you supply a negative step.