PHP
·
发表于 5年以前
·
阅读量:8296
from itertools import groupby
def height_class(h):
if h> 180:
return "tall"
elif h<160:
return "short"
else:
return "middle"
friends = [191,144,142,170,177,188,293]
friends = sorted(friends, key = height_class)
for m, n in itertools.groupby(friends, key=height_class):
print(m)
print(list(n))
#middle
#[170, 177]
#short
#[144, 142]
#tall
#[191, 188, 293]