Not sure if i am using dictionaries properly
I was trying to create a text analyzer with both dictionary and string formatting, but i seem to have gotten an error at the second last statement. It says: line 25 in <module> msg = ("{0} = {1}%".format(letters, dict(letters))) ValueError: dictionary update sequence element #0 has length 1; 2 is required. How do i solve this: #text analyzer #starting of the program textfile = input("Enter text document:") with open(textfile) as f: text = f.read() print(text) def count_char(text, char): count = 0 dict = {} for c in text: if c == char: count += 1 dict[char] = count*100/len(text) characters = ["abcdefghijklmnopqrstuvwxyz"] text = text.lower() for letters in characters: count_char(text, str(letters)) msg = ("{0} = {1}%".format(letters, dict(letters))) print(msg) EDIT: text = "Pretend that this is text in a file" print(text) def count_char(text, char): count = 0 dict = {} for c in text: if c == char: count += 1 dict[char] = count*100/len(text) characters = ["abcdefghijklmnopqrstuvwxyz"] text = text.lower() for letters in characters: count_char(text, str(letters)) msg = ('{0} = {1}%'.format(letters, dict[letters]))