我有一个包含数据的文件,我想要计算macaddress的数量: file.txt的:
块引用
D8:6C:E9:3C:77:FF ; 2016/01/10 14:02:47
D8:6C:E9:3C:77:FF ; 2016/01/10 14:02:47
D8:6C:E9:43:52:BF; 2016/01/10 13:41:29
F0:82:61:31:6B:88; 2016/01/10 13:43:41
8C:10:D4:D4:83:E5; 2016/01/10 13:44:35
54:64:D9:E8:64:36; 2016/01/10 13:46:13
18:1E:78:5A:CD:25; 2016/01/10 13:46:27
18:1E:78:5A:D7:A5; 2016/01/10 13:46:35
54:64:D9:75:1B:4B ; 2016/01/10 13:30:28
54:64:D9:75:1B:4B ; 2016/01/10 13:30:28 等....
我把它列入名单:
with open ('file.txt') as f:
mac = f.read().splitlines()
my_dic = {i:mac.count(i) for i in mac}
print my_dic
输出:
{' 18:1E:78:5A:D7:A5; 2016/01/10 13:46:35':1,' D8:6C:E9:3C:77: FF; 2016/01/10 14:02:47':2,' 64:64:D9:E8:64:36; 2016/01/10 13:46:13':1, ' D8:6C:E9:43:52:BF; 2016/01/10 13:41:29':1,' F0:82:61:31:6B:88; 2016 / 01/10 13:43:41':1,' 64:64:D9:75:1B:4B; 2016/01/10 13:30:28':2,' 18:1E:78:5A:CD:25; 2016/01/10 13:46:27':1,' 8C:10:D4:D4:83:E5; 2016/01/10 13 :44:35':1}
如何摆脱日期,因为我的预期:
{' 18:1E:78:5A:D7:A5:1,' D8:6C:E9:3C:77:FF:2,' 54:64:D9: E8:64:36:1,' D8:6C:E9:43:52:BF:1,' F0:82:61:31:6B:88:1,' 54: 64:D9:75:1B:4B:2,' 18:1E:78:5A:CD:25:1,' 8C:10:D4:D4:83:E5:1}