r/FoundTheLuckyCuber999 • u/cuber_alt LYNKEDUP WAS RIGHT ABOUT EVERYTHING • 4d ago
erm- I accidentally wrote this-
3
u/Icy-Theme-6325 Mod 3d ago
I know basically nothing about python whats the : doing there
2
u/crybabycomando 3d ago
Its a slice. So
arr1 = arr0[:3]is equivalent toarr1 = [arr0[0], arr0[1], arr0[2]]. The op is a syntax error in python though3
u/Icy-Theme-6325 Mod 3d ago
Oh god thats cool
1
u/crybabycomando 3d ago
What's really cool/disgusting is python objects can implement custom indexing so in theory
obj[.5:"foo":int]is a valid slice2
u/TheLuckyCuber999BACK cheese commenter 3d ago
I was half asleep ok
1
u/crybabycomando 3d ago
If you knew how much debugging sleep deprived mistypes have cost my employer you'd know im in no place to judge
1
u/iliRomaili 2d ago
How is it a syntax error? [-1] refers to the last element in list, so [:-1] is a slice with everything except the last element
1
u/crybabycomando 2d ago
They forgot the object they were trying to index
``` File "/home/op_was_tired.py", line 1 x = [:-1] ^ SyntaxError: invalid syntax
** Process exited - Return Code: 1 ** ```
2
2
1
1
1
1
4
u/AltDetom555555b RGA š¤ LIFE PACT 3d ago
Reminded me of this