python频率分析,

标签 python frequency analysis

到目前为止,我正在尝试创建一个频率分析程序。 到目前为止我已经:

`frequency_analysis = { "a" : 0,  "b" : 0,  "c" : 0,  "d" : 0,  "e" : 0,                      "f" : 0,  "g" : 0,
    "h" : 0,  "i" : 0,  "j" : 0,  "k" : 0,  "l" : 0,  "m" : 0,  "n" : 0,  "o" :   0,
    "p" : 0,  "q" : 0,  "r" : 0,  "s" : 0,  "t" : 0,  "u" : 0,  "v" : 0,  "w" : 0,
    "x" : 0,  "y" : 0,  "z" : 0 }

        listing = []

        letters = 'eatniroshlcdguwpbfynkvxzjq'
        alphabet = 'abcdefghijklmnopqrstuvwxyz'

        text = input("Please Enter text to decipher").lower()

        for letter in text:

            if letter.isalpha():
              frequency_analysis[letter] += 1

        def get_num (frequency_analysis):
            return frequency_analysis[1]


        unsorted_items = frequency_analysis.items()
        sorted_items = sorted(unsorted_items, key = get_num)

        descending = reversed(sorted_items)
        descending = list(descending)

        inorder = list()
        for char in descending:
            inorder.append(char)


        for key in inorder:

            if key[1] > 0:

                print (key)

我们现在需要将 key 与最常见的字母交换。
例如。输入:你好
查找频率:L,L,O,H,E
与代码顶部出现频率最高的字母(字母)交换。

L = E
o = A
H = T
E = n

然后按照hello的顺序放回去。

outcome = TNEEA

最佳答案

@tommy 的建议确实有帮助,但你必须通读一些文字。

>>> from collections import Counter
>>> c = Counter("Hello")
>>> c.most_common()

关于python频率分析,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29797475/

相关文章:

Python:如何将制表符转换为空格?

dplyr 的相对频率/比例

python - 查找数据框中每组另一个常见单元格中最常见的单元格

跨日志线相似性的算法分析?

objective-c - 使用 Xcode 分析(产品>分析)时,有没有办法忽略给定文件中的任何错误?

python - 通过将旧函数包装在其上来创建具有较少参数的新函数

python - 内置属性错误: 'module' object has no attribute 'one_tile'

python - 使用Flask和Flask-WTF中的路径和可选参数重定向到新页面不起作用

arduino - Arduino能否以1-4 kHz的微秒采样音频?

php - N-gram : Explanation + 2 applications