I have this code, in which we get info from a .txt file, that when I go through the .txt, and .split() them, I get a list with a format ["Party", "Gender", "Name", and 13 entries of numbers, in strings "" (for example: "1", "15", "3", etc)], I wanna add this info as a tuple in a list called distrito17.
data = open("votacion.txt", "r", encoding="UTF-8")
distrito17 = []
for infocandidato in data:
infocandidato=infocandidato.split()
total = #?
distrito17.append((infocandidato[:3], total)))
return distrito17
I know I can use this form:
... for vote in infocandidato[3:]
total+=int(vote)
And then add it to the list, but I was wondering if there is a way to use sum(), because I can do a sum(), which would help but the entries are strings, so I can't make a sum out of strings obviusly, but I have seen in some codes people use some kind of codes where:
sum(for i in infocandidato[3:], ... )
Or some sort, does anyone have a idea? Thanks in advance.