0

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.

enter image description here

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.

Progman
  • 16,827
  • 6
  • 33
  • 48
Sammy2021
  • 3
  • 3
  • Welcome to StackOverflow. Please read [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask), and in particular ask a question at all. What have you tried so far? Where did you struggle? Which programming language do you use at all? Show us your code and ask a specific question if you want to get help. – Manfred Oct 22 '22 at 12:02

1 Answers1

1

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)}')
rosa b.
  • 1,759
  • 2
  • 15
  • 18