Skip to content

Instantly share code, notes, and snippets.

@knowsuchagency
Created August 27, 2016 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knowsuchagency/4198bd96f433b42a2725432324cf8135 to your computer and use it in GitHub Desktop.
Save knowsuchagency/4198bd96f433b42a2725432324cf8135 to your computer and use it in GitHub Desktop.
in-class assignment
"""
Hello foo.
This line won't output.
Foo Bar.
foooooooooo
"""
# The above text is in the ./file.txt file
def lines_with_foo(filepath):
with open(filepath) as infile:
for line in infile:
if 'foo' in line.lower():
yield line
if __name__ == "__main__":
foo_lines = lines_with_foo("./file.txt")
[print(line) for line in foo_lines]
Hello foo.
This line won't output.
Foo Bar.
foooooooooo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment