3 ms·
> you want an easy way to express 0,1,2,...,n-1 I'm partial to the viciously set-theoretic[0]: for i in 5: print i # 0;1;2;3;4 0: finite ordinals[1] are 0=
by a1369209993 7y ago
> you want an easy way to express 0,1,2,...,n-1
I'm partial to the viciously set-theoretic[0]:
for i in 5: print i # 0;1;2;3;4
0: finite ordinals[1] are 0={},1={{}}={0},2={{},{{}}}={0,1},3={{},{{}},{{},{{}}}}={0,1,2},Sx=x∪{x}={0,...,x}
1: aka naturals or nonnegative/unsigned integers
- Zarel 7y agoThat only works if you're ranging from 0 to n-1, though. A popular way to partition an array at i and j is to do: arr[0..<i], arr[i..<j], arr[j...-1]
- a1369209993 7y agoa0,a1,a2 = arr.splitat({i,j}) maybe? It avoids repeating i and j twice and arr thrice, at least. Admittedly, there probably are cases where you really do want a range [x..^y] for arbitrary x and y, but it seems like most cases aren't.