本文实例讲述了Python实现统计给定列表中指定数字出现次数的方法。分享给大家供大家参考,具体如下:
直接看实现:
#!usr/bin/env python
#encoding:utf-8
'''''
__Author__:沂水寒城
功能:给定一个列表计数指定数字出现的所有次数
'''
def count_num_func(num_list,num):
  '''''
  计数指定数字
  '''
  split_list=[]
  for one in num_list:
    split_list+=list(str(one))
  print split_list.count(str(num))
if __name__ == '__main__':
  num_list=[1,12,34,56,112,1243,870,45,450,12,23,56]
  print "测试结果:"
  count_num_func(num_list,1)
  count_num_func(num_list,0)
结果如下:
PS:这里再为大家推荐2款非常方便的统计工具供大家参考使用:
在线字数统计工具:
http://tools.haodaima.com/code/zishutongji
在线字符统计与编辑工具:
http://tools.haodaima.com/code/char_tongji
希望本文所述对大家Python程序设计有所帮助。
以上就是Python实现统计给定列表中指定数字出现次数的方法。我们不是“居安思危”,而是“居危思进”。更多关于Python实现统计给定列表中指定数字出现次数的方法请关注haodaima.com其它相关文章!




