2004年09月24日 星期五 11:09
就像今天有位兄弟提出的那样各种邮件客户端在回复邮件时title里加的字符位置各不相同 那么有什么方法来快速的规类呢? 在python的标准库里有一个difflib 其中的get_close_matches很符合我们的需求 get_close_matches( word, possibilities[, n[, cutoff]]) Return a list of the best ``good enough'' matches. word is a sequence for which close matches are desired (typically a string), and possibilities is a list of sequences against which to match word (typically a list of strings). Optional argument n (default 3) is the maximum number of close matches to return; n must be greater than 0. Optional argument cutoff (default 0.6) is a float in the range [0, 1]. Possibilities that don't score at least that similar to word are ignored. The best (no more than n) matches among the possibilities are returned in a list, sorted by similarity score, most similar first. 例如: >>> difflib.get_close_matches("helo", ['test', 'Helo', 're:helo', 'Re:helo', 'RE: helo', 'helo Re:'], 5) ['Helo', 're:helo', 'Re:helo', 'helo Re:'] >>> -- I'm the one, powered by nEO
2004年09月24日 星期五 11:40
不错,这个话题值得讨论一下 On Fri, 24 Sep 2004 11:09:45 +0800, gentoo cn <gentoo.cn at gmail.com> wrote: > 就像今天有位兄弟提出的那样各种邮件客户端在回复邮件时title里加的字符位置各不相同 > 那么有什么方法来快速的规类呢? > > 在python的标准库里有一个difflib > 其中的get_close_matches很符合我们的需求 > get_close_matches( word, possibilities[, n[, cutoff]]) > > Return a list of the best ``good enough'' matches. word is a sequence > for which close matches are desired (typically a string), and > possibilities is a list of sequences against which to match word > (typically a list of strings). > Optional argument n (default 3) is the maximum number of close matches > to return; n must be greater than 0. > > Optional argument cutoff (default 0.6) is a float in the range [0, 1]. > Possibilities that don't score at least that similar to word are > ignored. > > The best (no more than n) matches among the possibilities are returned > in a list, sorted by similarity score, most similar first. > > 例如: > >>> difflib.get_close_matches("helo", ['test', 'Helo', 're:helo', > 'Re:helo', 'RE: helo', 'helo Re:'], 5) > ['Helo', 're:helo', 'Re:helo', 'helo Re:'] > >>> > > -- > I'm the one, powered by nEO > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > -- 欢迎访问:http://blog.csdn.net/ccat 刘鑫 March.Liu
Zeuux © 2025
京ICP备05028076号