I might be posting this prematurely, but I had an idea and wanted to float it. Also, I'm new here so hopefully this is appropriate.
How about augmenting slicing with an additional parameter 'size' (name chosen to achieve alliteration; 'start', 'stop', 'step', and 'size'), as such: >>> a_list = [0, 1, 2, 3, 4, 5, 6, 7] >>> a_list[1:5::4] # start=1, stop=5, step=1 (default), size=4 [(1, 2, 3, 4), (2, 3, 4, 5), (3, 4, 5, 6), (4, 5, 6, 7)] >>> a_list[::2:3] [(0, 1, 2), (2, 3, 4), (4, 5, 6)] # all tuples have length 3, even though data is left out >>> pairwise(a_list) == a_list[:::2] True >>> a_list[2:4] # step and size default to 1; size=1 returns the individual >>> list entries themselves not tuples [2, 3, 4] >>> a_list = urandom(1024) >>> a_list[::16:16] # 64 chunks of 16 bytes, no overlapping chunks In the case where the list is not evenly divisible by the provided parameters, I think for [] notation a guarantee that each item in the returned iterator will have len(item) == size is appropriate, rather than returning all the data even if len(item) < size; slice() could have enhanced parameters over and above [] notation that could allow for returning "deficient" items. A negative value size parameter could also be possible: >>> a_list = [0, 1, 2, 3, 4, 5, 6, 7] >>> a_list[:::-2] [(1, 0), (2, 1), (3, 2), (4, 3), (5, 4), (6, 5), (7, 6)] Thoughts? < Flash forward to 200 years from now. > >>> a_list[::::7:::::::::::::-1::] (42, 'of course!') _______________________________________________ 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/4N7UOAQRVLZFMDQJ6BKQ4GP3GQBGIGDH/ Code of Conduct: http://python.org/psf/codeofconduct/