with open("text.txt") as f: con = f.read() sc = con.count('success') fc = con.count('fail') d = {'success': sc,'fail': fc,} print(d)