In article <[email protected]>,
Marco <[email protected]> wrote:
> 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 sum() line is a bit of a mouthful. I would refactor it into
something like this:
> for line in open('data.txt'):
> fields = line.split(';')
> print sum(int(i) for i in fields)
It's the same number of lines, but I think it's easier to read.
BTW, are you using Python 2 or 3? It helps when asking these kinds of
questions to let people know. I assumed 2 in my answer above.
--
http://mail.python.org/mailman/listinfo/python-list