• python 字典统计次数


    # -*- coding:utf-8 -*-
    # !/usr/bin/python
    import sys
    reload(sys)
    sys.setdefaultencoding('utf8')
    import json
    import time
    path='E:ch02usagov_bitly_data2012-03-16-1331923249.txt'
    a= open(path).readlines()
    # print a
    print type(a)
    arr01=[]
    for x in a:
        #print x
        # print type(x)
        y=json.loads(x)
        for z in y:
            if z =='tz':
                # if y[z]:
                  print  str(z)+'=>'+str(y[z])
                  arr01.append(y[z])
        print '--------------------------------'
    print arr01
    def get_counts(sequence):
        counts={}
        for x in sequence:
            if x in counts:
                counts[x] += 1
            else:
                counts[x]=1
        return counts
    aa= get_counts(arr01)
    print aa
    print type(aa)
    for k in aa:
        print k+'=>'+str(aa[k])
  • 相关阅读:
    Vue(知识讲解)
    爬虫框架:scrapy
    爬虫性能相关
    MongoDB
    Beautifulsoup模块
    selenium模块
    requests模块
    爬虫(集锦)
    爬虫目录
    Flask目录
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348738.html
Copyright © 2020-2023  润新知