Topics covered in this episode:
About the show
Sponsored by ScoutAPM: pythonbytes.fm/scout
Connect with the hosts
Join us on YouTube at pythonbytes.fm/live to be part of the audience. Usually Tuesdays at 10am PT. Older video versions available there too.
Finally, if you want an artisanal, hand-crafted digest of every week of the show notes in email form? Add your name and email to our friends of the show list, we'll never share it.
Brian #1: Joining Strings in Python: A"Huh" Moment
Standard solution to “read lines from a file, do some filtering, create a multiline string”:
f = open("input_file.txt")filtered_text = "\n".join(x for x in f if not x.startswith("#"))
This uses a generator, file reading, and passes the generator to join.
Another approach is to add brackets and pass that generator to a list comprehension:
f = open("input_file.txt")filtered_text = "\n".join([x for x in f if not x.startswith("#")])
At first glance, this seems to just be extra typing, but it’s actually faster by 16% on CPython due to the implementation of .join() doing 2 passes on input if passed a generator.
Michael #2: 10 hard-to-swallow truths they won't tell you about software engineer job
Brian #3: My thoughts on Python in Excel
Michael #4: Extra, extra, extra
Extras
Brian:
Michael:
Joke: HTML Hacker
Podchaser is the ultimate destination for podcast data, search, and discovery. Learn More