List comprehension operators

It would be awesome to be able to create a list with just: li = [1—100] or li = [1 .. 100]

On Tue, Dec 14, 2021 at 03:46:06PM -0000, a.kolpakov2010--- via Python-ideas wrote:
It would be awesome to be able to create a list with just:
li = [1—100]
[1-100] already has a meaning in Python: it computes 1-100 = -99 and puts it in a list.
or
li = [1 .. 100]
Is that an open, closed, or half-open interval? -- Steve

If you didn't know, range objects already support most non-mutating list methods: >>> fakelist = range(1, 101) >>> fakelist[-1] 100 >>> fakelist[-10:] range(91, 101) >>> 50 in fakelist True >>> fakelist.index(50) 49 Range objects are more efficient than lists since they use O(1) memory instead of O(n), and many of the methods take O(1) time instead of O(n).

On Tue, Dec 14, 2021 at 03:46:06PM -0000, a.kolpakov2010--- via Python-ideas wrote:
It would be awesome to be able to create a list with just:
li = [1—100]
[1-100] already has a meaning in Python: it computes 1-100 = -99 and puts it in a list.
or
li = [1 .. 100]
Is that an open, closed, or half-open interval? -- Steve

If you didn't know, range objects already support most non-mutating list methods: >>> fakelist = range(1, 101) >>> fakelist[-1] 100 >>> fakelist[-10:] range(91, 101) >>> 50 in fakelist True >>> fakelist.index(50) 49 Range objects are more efficient than lists since they use O(1) memory instead of O(n), and many of the methods take O(1) time instead of O(n).
participants (5)
-
a.kolpakov2010@mail.ru
-
Ben Rudiak-Gould
-
Finn Mason
-
Simão Afonso
-
Steven D'Aprano