Don't forget to also checkout my second blog containing articles to all other related ICT topics!!

Thursday, May 3, 2012

Itertools dropwhile method explained

Itertools dropwhile makes an iterator that drops elements from the iterable as long as the predicate is true; afterwards, returns every element
from itertools import dropwhile

text = """#This is comment line 1
#This is comment line 2
    public abstract T getValue();
    public abstract void update(T object);"""

for line in dropwhile(lambda line: line.startswith('#'), text.split('\n')):
    print line

    public abstract T getValue();
    public abstract void update(T object);

No comments:

Post a Comment