python统计频数_python计算属性出现的频数

展开全部

参考2113代码:5261#coding: UTF-8

my_data = [

[1,1],

[1,2],

[1,3],

[1,4],

[2,1],

[2,2],

[2,3],

[2,4],

[3,1],

[3,2],

[3,3],

[3,4],

[4,1],

[4,2],

[4,3],

[4,4]

]

# print my_data

my_dic = {}

for (row_1, row_2) in my_data:

my_dic.setdefault(row_1, [])

my_dic[row_1].append(row_2)

for i in my_dic:

mylen = len(my_dic)

freq = max(my_dic[i])

for j in range(mylen):

print i, freq

输出4102:1653

1 4

1 4

1 4

1 4

2 4

2 4

2 4

2 4

3 4

3 4

3 4

3 4

4 4

4 4

4 4

4 4

[Finished in 0.1s]

你可能感兴趣的:(python统计频数)