A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2006-August/068512.html below:

[Python-Dev] Adding an rslice() builtin?

[Python-Dev] Adding an rslice() builtin? [Python-Dev] Adding an rslice() builtin?Nick Coghlan ncoghlan at iinet.net.au
Tue Aug 29 11:29:28 CEST 2006
A discussion on the py3k list reminded me that translating a forward slice 
into a reversed slice is significantly less than obvious to many people. Not 
only do you have to negate the step value and swap the start and stop values, 
but you also need to subtract one from each of the step values, and ensure the 
new start value was actually in the original slice:

   reversed(seq[start:stop:step]) becomes seq[(stop-1)%abs(step):start-1:-step]

An rslice builtin would make the latter version significantly easier to read:

   seq[rslice(start, stop, step)]

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4