字母组合计算

作者: 明慢慢 | 来源:发表于2015-12-02 16:51 被阅读116次

确定常用单词的各种字母组合频率

1.将单词切分成不同的字母组合
2.计算每个字母组合出现的次数

编码实现

#coding=utf-8
import fileinput
from collections import Counter
testword="find"
minslice=2
maxslice=5
cutnumber=2

def cut_word(inword,slicenumber):
    ddd=[]
    lenb=len(inword)
    for i in range(0,lenb,slicenumber):
        abc= inword[i:i+slicenumber]
        if len(abc)==slicenumber:
            ddd.append(abc)
    return ddd

def get_slice_list(inword,slicenumber):
    lll=[]
    lena=len(inword)
    for i in range(lena):
        aaa=inword[i:]
        lll.extend(cut_word(aaa,slicenumber))
        mylist=list(set(lll))
    return mylist

def get_all_slice_list(inword):
    lll=[]
    for i in range(minslice,maxslice+1):
        lll.extend(get_slice_list(inword,i))
    return lll

alllist=[]
for line in fileinput.input( "1.txt" ):
    aaa=line.rstrip()
    print "read   :%s"%(aaa)
    alllist.extend(get_all_slice_list(aaa))
c=Counter(alllist).most_common()


print "##########begin write file..."
output = open('jieguo.txt', 'w')
for i in c:
    output.write("%s,%d\n"%i)
output.close()

print "##########write end"

相关文章

  • 字母组合计算

    确定常用单词的各种字母组合频率 1.将单词切分成不同的字母组合2.计算每个字母组合出现的次数 编码实现

  • 11

    图样单词记忆法之字母组合编码法 一、字母组合编码法 26个字母有单字母编码,其实字母组合也有字母组合的编码。 字母...

  • 【发音笔记一】单元音[i]和[I]

    单元音 [i]——长音 常见字母组合:ee,ea,ie,ei,ey 单元音[I]——短音 常见字母组合:i,e,a...

  • 【发音】字母组合“ee”发音规律:/iː/

    今天要介绍的字母组合ee的发音。 字母组合ee发的是长音/iː/的音,如: indeed /ɪnˈdiːd/ a...

  • 【leetcode】电话号码的字母组合

    【leetcode】电话号码的字母组合 题目: 给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合。...

  • [德语发音]——辅音字母组合发音

    过年好忙差点忘了这块儿了哈哈,今天给大家分享一下辅音字母组合的发音规则。 1、辅音字母组合ch 在元音a o u ...

  • LeetCode #1286 Iterator for Comb

    1286 Iterator for Combination 字母组合迭代器 Description: Design...

  • 字母组合gg和gh的发音很简单

    今天我们来学习字母组合gg和gh的发音。它们的发音规则比较简单,详见下图: 字母组合gg的发音 1.发/g/的音 ...

  • LeetCode017:电话号码的字母组合

    题目介绍 题目:电话号码的字母组合描述:给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合。给出数字...

  • LeetCode:电话号码的字母组合

    电话号码的字母组合 题目叙述: 给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合。 给出数字到字母...

网友评论

    本文标题:字母组合计算

    本文链接:https://www.haomeiwen.com/subject/gdbkhttx.html