Skip to content

Instantly share code, notes, and snippets.

@zacharysyoung
Last active April 7, 2022 16:25
Show Gist options
  • Save zacharysyoung/6fc91484bde1c77c3773f945685e44ac to your computer and use it in GitHub Desktop.
Save zacharysyoung/6fc91484bde1c77c3773f945685e44ac to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# https://stackoverflow.com/a/71784820/246801
# Misses "interior" extraneous whitespaces
block = ["Line 1\n", " Line 2\n", "Line 3\n"]
list_comp = [x.strip() for x in block]
func_chain = "".join(block).strip().split("\n")
assert list_comp == func_chain
# Completely fails
block = ["Line 1\r\n", " Line 2\r\n", "Line 3\r\n"]
list_comp = [x.strip() for x in block]
func_chain = "".join(block).strip().split("\n")
assert list_comp == func_chain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment