Not understanding itertools.dropwhile()

Peter Otten __peter__ at web.de
Sun Apr 30 03:19:46 EDT 2017


Jason Friedman wrote:

> def test_to_start(s):
>     return "2" in s
> 
> for line in itertools.dropwhile(test_to_start, data.splitlines()):
>     print(line)

It's really all in the names: it could either be

for line in dropwhile(test_to_drop, items):
    ...

or

for line in dropwhilenot(test_to_start, items):
    ...
 
> <---- end code ---->
> 
> I expect:
> 
> $ python3 dropwhile.py
> Line2
> 
> Line4
> Line5
> 
> 
> I get:
> 
> $ python3 dropwhile.py
> Line1
> Line2
> 
> Line4
> Line5
> 
> 
> Please explain.




More information about the Python-list mailing list