4 ms·
Show HN: Intspan, because 1,3-7 is better than [1,3,4,5,6,7]
- nicolewhite 11y agoNeat. This is something that R does out of the box: > s = c(1:3, 14, 29, 92:97) > s [1] 1 2 3 14 29 92 93 94 95 96 97 I think I prefer the 1:3 syntax versus 1-3, especially when dealing with negative numbers. In R: > -6:-3 [1] -6 -5 -4 -3 In intspan: >>> s = intspan('-6--3') >>> list(s) [-6, -5, -4, -3] So the syntax is a little funky. Another thing is that R will allow you to go from big to small: > 2:-3 [1] 2 1 0 -1 -2 -3 Whereas intspan doesn't seem to support this at all: >>> s = intspan('2--3') >>> list(s) [] Very cool though!
- jonathaneunice 11y agoIntspan's string representation was inspired by network news / UUCP, back in the first days of Usenet / Internet before the real Internet. So it was really only designed for whole numbers, not negatives. The syntax for negatives IS very clunky, mostly because they are rarely exercised/used in most of the use cases. I like that "generalized range" operator from R. And it's a nice closed interval, not the half-open annoyance of Python's range() function.