0

I'm trying to make a coding program that uses frequency analysis (which is the process of looking at a string of letters, then adding one to the total times you've seen that letter). What I think I'm trying to do is something like

for letter in code_reader: 
      letter+(_value) += 1

In practice, it would look at letter "x", insert it into the format (letter)_value, and then add 1 to it. I think my main problem is the fact that I can't add a string to a variable, but I was hoping some of you smart people out there could help!

Pikachu123
  • 11
  • 1
  • 6
    Do you know about dictionaries? https://docs.python.org/3/tutorial/datastructures.html – Nathan Hughes Aug 03 '21 at 18:07
  • 2
    Or ccollections.Counter https://docs.python.org/3/library/collections.html?highlight=counter#collections.Counter – DisappointedByUnaccountableMod Aug 03 '21 at 18:07
  • @NathanHughes Ah, thanks! Will try to see if it'll work better that way! – Pikachu123 Aug 03 '21 at 18:08
  • 1
    You have several blocking points in attacking the problem at hand. First, you need to become familiar with variable names and values, and how you can manipulate those values (manipulating the names is highly dangerous). Then, learn data agglomerations: lists, strings, dicts, etc. In particular, the object `collections.Counter` will solve your problem quickly. – Prune Aug 03 '21 at 18:10

0 Answers0