>>> words[random.randint(0, len(words))]
'Please send me a DM if you send me a follow request'
>>> words[random.randint(0, len(words))]
'Windows 10'
>>> words[random.randint(0, len(words))]
'racism'
>>> words[random.randint(0, len(words))]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list index out of range

why?
Follow

@kirby
I mean indices start with zero, but length of array that only has element with index 0 is still 1.

@m0xee @kirby WTF kind of rng uses a closed interval tho? shouldn't it be half open :blobwoozy:

@roboneko
Honestly, dunno. People writing in Python always throw new shit at me, I'm pretty sure, this randint thing is decades old already, but I still live in the days when you had to multiple, round down and convert to integer yourself 🤪
Good documentation is the strong side of Python, very thorough, with great examples, usually mentioning all the caveats. Although I've seen some weird shit about asynchronous stuff in 3.10 docs, they are changing things too often now 🤷
@kirby

Sign in to participate in the conversation
Librem Social

Librem Social is an opt-in public network. Messages are shared under Creative Commons BY-SA 4.0 license terms. Policy.

Stay safe. Please abide by our code of conduct.

(Source code)

image/svg+xml Librem Chat image/svg+xml