<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 9 June 2018 at 19:20, Michel Desmoulin <span dir="ltr"><<a href="mailto:desmoulinmichel@gmail.com" target="_blank">desmoulinmichel@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Given 2 callables checking when a condition arises and returning True:<br>
<br>
def starting_when(element):<br>
...<br>
<br>
def ending_when(element:<br>
...<br>
Allow:<br>
<br>
a_list[starting_when:]<br>
<br>
To be equivalent to:<br>
<br>
from itertools import dropwhile<br>
<br>
list(dropwhile(lambda x: not starting_when(x), a_list))<br></blockquote><div><br></div>Custom container implementations can already do this if they're so inclined, as slice objects don't type check their inputs:</div><div class="gmail_quote"><br></div><div class="gmail_quote"> >>> class MyContainer:<br> ... def __getitem__(self, key):<br> ... return key<br> ... <br> >>> mc = MyContainer()<br> >>> mc[:bool]<br> slice(None, <class 'bool'>, None)<br> >>> mc[bool:]<br> slice(<class 'bool'>, None, None)<br> >>> mc[list:tuple:range]<br> slice(<class 'list'>, <class 'tuple'>, <class 'range'>)</div><div class="gmail_quote"><br></div><div class="gmail_quote">It's only slice.indices() that needs start/stop/step to adhere to the Optional[int] type hint.<br></div><div class="gmail_quote"><br></div><div class="gmail_quote">Cheers,</div><div class="gmail_quote">Nick.<br clear="all"></div><br>-- <br><div class="gmail_signature">Nick Coghlan | <a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a> | Brisbane, Australia</div>
</div></div>