IPython 读取USER_AGENT数据统计操作系统

user_devices = [rec['a'] for rec in records if 'a' in rec]

# 

def device_counts(seq):
    counts = {}
    devices = {'Windows','compatible','iPhone','iPad','BlackBerry','Macintosh','Linux'}
    for name in devices:
        counts[name] = 0
    
    for x in seq:
        for name in devices:
            if name in x:
                counts[name]+=1
    return counts
        
            
            

# 

acounts = device_counts(user_devices)

你可能感兴趣的:(IPython 读取USER_AGENT数据统计操作系统)