根据给出的房源信息,用Python实现输出挂牌价最低的三套房源信息,以及输出人气最高的三套房源信息。
代码如下:
dict_house={'001':["3室1厅",68.69,"南北","简装",37124,35],
'002':["2室2厅",87.16,"南西","精装",37375,148],
'003':["3室1厅",61.72,"南北","精装",37266,146],
'004':["3室2厅",68.18,"南北","精装",68496,79],
'005':["2室2厅",71.67,"南","简装",33487,105],
'006':["3室1厅",84.78,"南北","简装",51782,34]}
list_s=[]
for i,j in dict_house.items():
T=list(j)
T.insert(0,i)
list_s.append(list(T))
T.clear()
list_s.sort(key=lambda x:x[5])
print("挂牌价最低的三套房源信息:")
for i in range(0,3):
s=[str(x) for x in list_s[i]]
print(" ".join(s))
del s
list_s.sort(key=lambda x:x[6])
print("人气最高的三套房源信息:")
for i in range(-1,-4,-1):
s=[str(x) for x in list_s[i]]
print(" ".join(s))
del s
运行结果如下:
菜菜的代码,希望能够帮助到你哟!