[issue42956] Easy conversion between range and slice

2021-01-18 Thread Raymond Hettinger
Raymond Hettinger added the comment: Perhaps the indices() method will suffice: >>> slice(None, 10, 2).indices(8) (0, 8, 2) >>> range(8)[:10:2] range(0, 8, 2) -- nosy: +rhettinger ___ Python tracker

[issue42956] Easy conversion between range and slice

2021-01-18 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: > s.start or 0 Why 0? start=None is not the same as start=0 in slice. For example: >>> 'abcdefgh'[slice(None, 3, -1)] 'hgfe' >>> 'abcdefgh'[slice(0, 3, -1)] '' Slices and range objects are very different in many ways. It depends on your application how

[issue42956] Easy conversion between range and slice

2021-01-18 Thread Steven D'Aprano
Steven D'Aprano added the comment: All versions older than 3.10 are in feature freeze and cannot get new features or enhancements, only bugfixes. Slices are far more general than range objects. How do you propose to deal with slice objects such as this? slice('item', (23, {'key':

[issue42956] Easy conversion between range and slice

2021-01-18 Thread Dávid Nemeskey
Dávid Nemeskey added the comment: s/to different/two different/ -- ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue42956] Easy conversion between range and slice

2021-01-18 Thread Dávid Nemeskey
New submission from Dávid Nemeskey : It would be nice if there was an easy way to convert a range to a slice and vice versa. At least superficially the two are almost the same(*), yet if one wants to convert a slice to a range, he has to go through hoops to avoid potential errors, ending up