python找出字符串中每个字母出现的次数
2017-03-01 22:17
405 查看
#完全用列表方式实现 #!/usr/bin/env python # coding=utf-8 str1 = "abcdefabcdefgghj" listStr = [] for eachStr in str1: countStr = str1.count(eachStr) numStr = eachStr + ":" + str(countStr) if numStr not in listStr : listStr.append(numStr) for i in listStr: print i ############用字典方式实现################ #!/usr/bin/python # coding=utf-8 d = {} for s in ['c','c','c++','python','python','python','js']: if s in d: d[s] = d[s] + 1 else: d[s] = 1 for key in d: print('%s count is %d')%(key,d[key])
相关文章推荐
- [python] 判断字符串中出现次数最多的字母
- 第十三周OJ项目统计每个元音字母在字符串中出现的次数。
- 找出字符串中出现次数最多的字母和出现次数精简版
- 统计一个字符串中每个字母出现的次数
- 问题6: 找出字符串中出现次数最多的字母及其出现的次数
- 超初级的用Python收集杂乱字符串中的特定字符,统计出每个特定字符的出现次数并取出最小值
- 面试编程题1:给定一个字符串,统计出每个字母出现次数
- 统计字符串中每个字母出现的次数
- 获取字符串中每个字母出现的次数
- python 获取字符串中出现次数最多的字母
- 统计字符串中每个字母出现的次数。
- 一道迅雷面试题:求出一个字符串中每个字母出现的次数
- C# 在一个字符串中,找出出现次数最多的字母,并计算次数?
- java实现计算出字符串中每个字母出现次数
- 超初级的用Python收集杂乱字符串中的特定字符,统计出每个特定字符的出现次数并取出最小值
- Java 统计一个字符串中每个单词,或者字母出现的次数
- 用java编写一个函数,统计一个字符串中每个字母出现的次数
- 找出字符串中出现次数最多的字母和出现的次数
- Q7.1.3 找出字符串中出现最多的字母及次数
- java面试题:输出字符串每个字母出现的次数