Write to a file in Python with open(filename, ‘w’). What if filename already exists? Its contents are gone. (I hope you have backups!) Instead, try: If filename already exists, ‘x’ raises an exception. For new files, ‘x’ and ‘w’ are the same.
Use parentheses to split long Python code across lines: But with parentheses, Python sees it as one line: Or in comprehensions…