Python杂技1

Python杂技1,第1张

概述In[4]:importheapqIn[6]:topK=2In[7]:item_score_dict={'a':1,'b':2}#从字典中In[8]:rank=heapq.nlargest(topK,item_score_dict,key=item_score_dict.get)#返回的是[b,a]>>>importheapq#从列表中>>>nums=[1,8,2,2
In [4]: import heapqIn [6]: topK = 2In [7]: item_score_dict = {'a':1,'b':2} # 从字典中In [8]: rank = heapq.nlargest(topK,item_score_dict,key = item_score_dict.get) # 返回的是[b,a]>>> import heapq # 从列表中>>> nums=[1,8,2,23,7,-4,18,23,42,37,2]>>> print(heapq.nlargest(3,nums))[42, 37, 23]>>> print(heapq.nsmallest(3,nums))[-4, 1, 2]# 一种比较好的打印方式sys.stdout.write('\r{} / {} : loss = {}'.format(                    i, num_batches, np.mean(losses[-verbose:])                ))sys.stdout.flush()

 

总结

以上是内存溢出为你收集整理的Python杂技1全部内容,希望文章能够帮你解决Python杂技1所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1188493.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存