DEV Community

loading...

Discussion on: Python tips and trick, you haven't already seen

Collapse
rhettbull profile image
Rhet

Thanks — very useful tips. FYI, the “Skipping beginning of iterable” example doesn’t behave as expected for me because the first line in the string is just a \n. To get it to behave as expected, I had to change your snippet to:

string_from_file = """// Author: ...
// License: ...
//
// Date: ...

Actual content...

"""

import itertools

for line in itertools.dropwhile(lambda line: line.startswith("//"), string_from_file.split("\n")):
    print(line)
Collapse
martinheinz profile image
Martin Heinz Author

Yep, you are right, thanks. It worked when I was testing it, but probably added extra new line when I was copying it to blog. Good catch! :)