I'm currently trying to create a function that counts the frequency of characters in in a string. I need to store it in a dictionary in ASCII code. From this dictionary I need to calculate which letters do not appear in the string.
import string
result=string.ascii_uppercase
print(result)
string_1 = 'WSXFGTYUJNMKLOIUYGFDXCVBHJKLMNBVFDEW'
frequencies = {}
for char in string_1:
if char in frequencies:
frequencies[char] +=1
else:
frequencies[char]=1
print("per char frequenct in '{}'is :\n{}".format(string_1, str(frequencies)))
list(string_1.encode('ascii'))
alphabet=set(ascii_uppercase)
def find_missing_letter(string_1)
return alphabet - (string_1)
Print(find_missing_letter(string_1))
I've managed most of it just cant get it to identify which letters are not present in the string.
You are almost there. Just transform the string to a set first, then subtract the letters from the letters of the alphabet.
def find_missing_letter(string_1):
return set(string.ascii_uppercase) - set(string_1)
result = find_missing_letter(string_1)
print(result) # {'A', 'P', 'Q', 'R', 'Z'}
print(f'Number of missing letters: {len(result)}')