鉴于:
from collections import Counter
class TEST:
age = 'unknown'
city = 'unknown'
def __init__(self, a, c):
self.age = a
self.city = c
def __repr__(self):
return "(" + str(self.age) + "," + self.city + ")"
L = [TEST(20, 'LA'), TEST(30, 'NY'), TEST(30, 'LA')]
我想计算“城市”属性的频率:
期望的输出:
[[20, 'LA', 2], [30, 'NY', 1], [30, 'LA', 2]]