Skip to content

Instantly share code, notes, and snippets.

@paulofreitas
Last active December 27, 2015 10:09
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 paulofreitas/7309152 to your computer and use it in GitHub Desktop.
Save paulofreitas/7309152 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# Alteração in-place
with open('dados1.txt', 'r+w') as f:
lines = [' '.join(l.split() + [str(reduce(lambda x, y: x * y, map(int, l.split())))]) for l in f]
f.seek(0)
f.write('\n'.join(lines))
# Dois arquivos
open('dados2.txt', 'w').write('\n'.join(' '.join(l.split() + [str(reduce(
lambda x, y: x * y, map(int, l.split())))]) for l in open('dados1.txt')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment