A RetroSearch Logo

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

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-January/051279.html below:

[Python-Dev] Allowing slicing of iterators

[Python-Dev] Allowing slicing of iterators [Python-Dev] Allowing slicing of iteratorsNick Coghlan ncoghlan at iinet.net.au
Tue Jan 25 14:41:32 CET 2005
Batista, Facundo wrote:
> I think that breaking the common idiom...
> 
>   for e in something[:]:
>       something.remove(e)
> 
> is a no-no...

The patch doesn't change existing behaviour - anything which is already 
sliceable (e.g. lists) goes through the existing __getitem__ or __getslice__ 
code paths.

All the patch adds is two additional checks (the first for an iterator, the 
second for an iterable) before PyObject_GetItem fails with the traditional 
"TypeError: unsubscriptable object".

Defining __getitem__ also allows any given iterator or iterable type to override 
the default slicing behaviour if they so choose.

Regards,
Nick.

-- 
Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net
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