f = open("file"); str = f.read(); f.close(); priority = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] splitted = [] str = str.split("\n") while len(str) != 0: splitted.append("\n".join(str[:3])); str = str[3:]; sum = 0; for group in splitted: resplitted = group.split("\n"); print(resplitted) for i in resplitted[0]: if (i in resplitted[1] and i in resplitted[2]): sum += priority.index(i) + 1; break; print (sum);