M
Marco
Hi all, do you think this code:
$ more myscript.py
for line in open('data.txt'):
result = sum(int(data) for data in line.split(';'))
print(result)
that sums the elements of the lines of this file:
$ more data.txt
30;44;99;88
11;17;16;50
33;91;77;15
$ python3.3 myscript.py
261
94
216
is explicit enough? Do you prefer a clearer solution?
Thanks in advance, Marco
$ more myscript.py
for line in open('data.txt'):
result = sum(int(data) for data in line.split(';'))
print(result)
that sums the elements of the lines of this file:
$ more data.txt
30;44;99;88
11;17;16;50
33;91;77;15
$ python3.3 myscript.py
261
94
216
is explicit enough? Do you prefer a clearer solution?
Thanks in advance, Marco