Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def solveit(file_name = "challenge9_list.txt"):
- f = open(file_name, "r")
- contents = [i[0] for i in f.readlines() if (ord(i[0]) >= ord('a') or ord(i[0]) <= ord('z')) or (ord(i[0]) >= ord('0') or ord(i[0]) <= ord('9'))]
- f.close()
- sumdigit = 0
- alpha = [0 for i in range(26)]
- for i in contents:
- if ord(i) >= ord('0') and ord(i) <= ord('9'):
- sumdigit += int(i)
- else:
- alpha[ord(i) - ord('a')] += 1
- result = "Sum = {0}\n".format(sumdigit)
- for i in range(0,26):
- if alpha[i] != 0:
- result += "'{0}' = {1}\n".format(chr(i + ord('a')), alpha[i])
- return result
- if __name__ == "__main__":
- print(solveit())
- input() # pausa
Advertisement
Add Comment
Please, Sign In to add comment