heapsort 在heapq.py模块,可以快速排序,堆排序

https://www.cnblogs.com/Joyce-song94/p/7149440.html

 

heapq.nsmallest(niterable[, key])

Return a list with the n smallest elements from the dataset defined by iterablekey, if provided, specifies a function of one argument that is used to extract a comparison key from each element in the iterablekey=str.lower Equivalent to: sorted(iterable, key=key)[:n]

 

堆排序

 

set1 = set()
set1.add(1)
set1.add(2)
set1.add(3)

d = {}
d[0]=-1
d[1]=4
d[2]=5
d[3]=6

a = [1, 5, 2, 1, 9, 1, 5, 10]
order = hp.nsmallest(len(d),d)
for i in order: 
    if i in set1:
        print("smallest in set1 is ",i)
        break
print("ok")

#result

#对字典排序

https://blog.youkuaiyun.com/qq_41800366/article/details/86253908

 

#python lamda表达式

https://www.cnblogs.com/jszfy/p/11148963.html

 

 

字典是否可迭代

https://www.cnblogs.com/wangbin2188/p/6532510.html

 

 

smallest in set1 is  1
ok
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值