import string def pr1(): print("A", {i*i for i in range(1001) if i%10 == 5}) print("B", {i*j for i in range(1,100) for j in range(1,100) if i%10 == 5 and j%10 == 5}) print("C", {i*j*k for i in range(1, 10) for j in range(1, 10) for k in range(1, 10) if \ i!=j and j!=k and i!=k}) def pr2(): return {x:0 for x in string.ascii_letters} def pr3(astring): # The usual pattern for checking. If we find a good character, we know that the string is good. #But we can only say that a string is bad if _all_ letters have been investigated. for character in astring: if character in string.ascii_letters: return True return False def pr4(file_name): with open(file_name) as inf: line_counter, word_counter, letter_counter = 0, 0, 0 for line in inf: if len(line)>1: line_counter += 1 for word in line.split(): if pr3(word): word_counter += 1 for character in line: if character in string.ascii_letters: letter_counter += 1 return line_counter, word_counter, letter_counter def pr5(file_name): with open(file_name) as inf: for line in inf: for word in line.split(): word = word.strip(string.punctuation) try: print(int(word)) except ValueError: pass