Skip to content

Instantly share code, notes, and snippets.

@fcschmidt
Created June 12, 2017 15:15
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 fcschmidt/b327f9da877e763f7f0a074c7369637e to your computer and use it in GitHub Desktop.
Save fcschmidt/b327f9da877e763f7f0a074c7369637e to your computer and use it in GitHub Desktop.
Question asked in the facebook python community
#!/usr/bin/env python3
"""
Uma matrix é formada por vetores
Ex:
m = [[1, 1234, 567, 890, 10],
[1, 1234, 567, 890, 10],
[1, 1234, 567, 890, 10]]
Ou, seja:
matrix 3x5 == 3 linha, 5 coluna
0 1 2 3 4
[1, 1234, 567, 890, 10]
[1, 1234, 567, 890, 10]
[1, 1234, 567, 890, 10]
Pegar a coluna 2, 3 e 4 == (1, 2 e 3), somar +1
deixar as outras com o valor original.
input_file:
1 1234 567 890 10
1 1234 567 890 10
1 1234 567 890 10
1 1234 567 890 10
1 1234 567 890 10
output_file:
1 1235 568 891 10
1 1235 568 891 10
1 1235 568 891 10
1 1235 568 891 10
1 1235 568 891 10
"""
input_file = 'input_file.txt'
output_file = 'output_file.txt'
matrix = []
for row in open(input_file, 'rb'):
c_int = [int(z) for z in row.split()]
if len(c_int) == 0:
pass
else:
vector = []
col = 0
while col <= 4:
if col == 0:
vector.append(str(c_int[col]))
col += 1
else:
if col <= 3:
vector.append(str(c_int[col] + 1))
else:
vector.append(str(c_int[col]))
col += 1
matrix.append(vector)
with open(output_file, 'w') as o:
for m in matrix:
o.write('{}\n'.format(' '.join(m)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment