On 9 June 2018 at 19:20, Michel Desmoulin <[email protected]> wrote:
> Given 2 callables checking when a condition arises and returning True:
>
> def starting_when(element):
> ...
>
> def ending_when(element:
> ...
> Allow:
>
> a_list[starting_when:]
>
> To be equivalent to:
>
> from itertools import dropwhile
>
> list(dropwhile(lambda x: not starting_when(x), a_list))
>
Custom container implementations can already do this if they're so
inclined, as slice objects don't type check their inputs:
>>> class MyContainer:
... def __getitem__(self, key):
... return key
...
>>> mc = MyContainer()
>>> mc[:bool]
slice(None, <class 'bool'>, None)
>>> mc[bool:]
slice(<class 'bool'>, None, None)
>>> mc[list:tuple:range]
slice(<class 'list'>, <class 'tuple'>, <class 'range'>)
It's only slice.indices() that needs start/stop/step to adhere to the
Optional[int] type hint.
Cheers,
Nick.
--
Nick Coghlan | [email protected] | Brisbane, Australia
_______________________________________________
Python-ideas mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/