[Python-ideas] Re: Creating ranges with ellipsis
[:y] would just mean [0:y]. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/ODU564CAHGUJZKB3ZVNXIQ6RKIVW3CJX/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Creating ranges with ellipsis
> > > This might be a silly idea but, would it be a good idea to have > > ...[a:b:c] return a range(a, b, c)? > If a 'thunderscore' is acceptable: import itertools class _ranger: @classmethod def __getitem__(self, key: slice): if isinstance(key, slice): if key.stop is None: return itertools.count(key.start, key.step or 1) return range(key.start, key.stop, key.step or 1) return range(key) ___ = _ranger() Trying to write it brings out lots of questions like what would [:y] do, or [:], [::z], etc. Only [x], [x:y], [x:], [x::z], [x:y:z] seem to make sense. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/WARMRS7GMQHYEBGR5FTBKHW436DWRWW6/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Creating ranges with ellipsis
> This might be a silly idea but, would it be a good idea to have > ...[a:b:c] return a range(a, b, c)? This sort of highly-subjective syntactic sugar makes me wonder whether there would be support for a standard python preprocessor, like what was suggested in PEP 638 [1]. [1]: https://www.python.org/dev/peps/pep-0638/ - DLD ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/CY2YRG6TCAT5GXB7EKCCCHSKQPS6ZSQE/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Creating ranges with ellipsis
16.02.22 14:44, Soni L. пише: > This might be a silly idea but, would it be a good idea to have > ...[a:b:c] return a range(a, b, c)? See PEP 204. https://www.python.org/dev/peps/pep-0204/ ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/KOJRH7UHMQEMZN4IPB6TT7NXOQNZAFVT/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Creating ranges with ellipsis
On 2022-02-16 10:45, Steven D'Aprano wrote: > On Wed, Feb 16, 2022 at 09:44:07AM -0300, Soni L. wrote: > > This might be a silly idea but, would it be a good idea to have > > ...[a:b:c] return a range(a, b, c)? > > Similar ideas have been suggested before: > > https://mail.python.org/archives/list/python-ideas@python.org/thread/W44PPBJJXETTBQHWCMJB3DRCD6CTXWJT/ > > https://bugs.python.org/issue42956 > > What benefit do you see in writing [a:b:c] instead of range(a, b, c)? > > > *nod* we see. syntax constructs like these are mostly about taste. it's like being able to write generators in function calls like list(x for x in foo), but also having (x for x in foo) instead of using a gen(x for x in foo) function. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/G2ZYUPM5MARUMELUV4FDDHJS6O6H42TB/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Creating ranges with ellipsis
On Wed, Feb 16, 2022 at 09:44:07AM -0300, Soni L. wrote: > This might be a silly idea but, would it be a good idea to have > ...[a:b:c] return a range(a, b, c)? Similar ideas have been suggested before: https://mail.python.org/archives/list/python-ideas@python.org/thread/W44PPBJJXETTBQHWCMJB3DRCD6CTXWJT/ https://bugs.python.org/issue42956 What benefit do you see in writing [a:b:c] instead of range(a, b, c)? -- Steve ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/26HCWBERDZKAC5H2A2PAOLIMMPTDPIZW/ Code of Conduct: http://python.org/psf/codeofconduct/