# 有趣，用Python算算哪个星座富豪最多！

```def cal_constellation(month, day):
constellation = (u'摩羯座',u'水瓶座',u'双鱼座',u'白羊座',u'金牛座',u'双子座',u'巨蟹座',u'狮子座',u'处女座',u'天秤座',u'天蝎座',u'射手座')
start_day = ((1,20),(2,19),(3,21),(4,21),(5,21),(6,22),(7,23),(8,23),(9,23),(10,23),(11,23),(12,23))
return constellation[len(list(filter(lambda y:y&lt;=(month,day), start_day)))%12]```

## 1.获得数据

(\d+) ?月 ?(\d+) ?日

## 2.放入代码计算

```birth_day = [
(1, 28), (10, 28), (8, 30), (3, 5), (3, 28), (8, 17), (11, 3), (10, 4), (7, 29), (2, 20), (11, 1),
(5, 3), (8, 4), (10, 21), (7, 7), (10, 7), (10, 28), (4, 19), (2, 14), (6, 15), (8, 12), (4, 26),
(8, 21), (3, 26), (1, 12), (4, 2), (9, 9), (3, 7), (2, 20), (2, 9), (3, 28), (11, 5), (4, 16), (1, 14),
(4, 12), (6, 12), (9, 1), (5, 14), (9, 21), (8, 26), (2, 23), (5, 7), (7, 24), (3, 24), (9, 26), (1, 3),
(2, 24), (1, 21), (7, 8), (2, 16), (8, 16), (10, 10), (9, 1), (4, 21), (5, 3), (4, 28), (8, 21), (12, 1),
(12, 14), (10, 6), (1, 27), (4, 14), (6, 4), (10, 24), (5, 11), (8, 26), (1, 1), (6, 14), (8, 11), (5, 22),
(5, 10), (4, 10), (5, 9), (12, 22), (12, 11), (3, 20), (3, 8), (9, 22), (12, 19), (11, 17), (9, 15), (3, 25),
(2, 7), (4, 4), (4, 1), (6, 2), (2, 13), (11, 8)
]
def cal_constellation(month, day):
constellation = (u'摩羯座',u'水瓶座',u'双鱼座',u'白羊座',u'金牛座',u'双子座',u'巨蟹座',u'狮子座',u'处女座',u'天秤座',u'天蝎座',u'射手座')
start_day = ((1,20), (2,19), (3,21), (4,21), (5,21), (6,22), (7,23), (8,23), (9,23), (10,23), (11,23), (12,23))
return constellation[len(list(filter(lambda y:y&lt;=(month,day), start_day)))%12]

result = {}
for birth in birth_day:
constel = cal_constellation(birth[0], birth[1])
if constel not in result:
result[constel] = 0
else:
result[constel] += 1
print(result)```

{'水瓶座': 7, '天蝎座': 7, '处女座': 8, '双鱼座': 7, '白羊座': 12, '狮子座': 8, '天秤座': 5, '金牛座': 9, '巨蟹座': 1, '双子座': 5, '摩羯座': 3, '射手座': 4}

`print(sorted(result.items(), key=lambda item: item[1]))`

[('巨蟹座', 1), ('摩羯座', 3), ('射手座', 4), ('天秤座', 5), ('双子座', 5), ('水瓶座', 7), ('天蝎座', 7), ('双鱼座', 7), ('处女座', 8), ('狮子座', 8), ('金牛座', 9), ('白羊座', 12)]

​Python实用宝典 (pythondict.com)