Python
分享Python的相关知识和常用技巧
SincX
向AI编译器方向努力
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Python collections.Counter(s)
Python collections.Counter(s) 统计字符串s中各个字符的个数 s = "loveleetcode" # build hash map : character and how often it appears count = collections.Counter(s) 结果:原创 2020-05-26 16:03:46 · 1120 阅读 · 0 评论 -
Python 字典(dict)的默认值(defaultdict)和排序(sorted)
Python 字典(dict) 默认值defaultdict defaultdict的作用是在于,当字典里的key不存在但被查找时,返回的不是keyError而是一个默认值 from collections import defaultdict dic1 = defaultdict(int) dic2 = defaultdict(set) dic3 = defaultdict(list)) print(dict1[1]) print(dict2[1]) print(dict3[1]) 输出: 0 set(原创 2020-05-25 18:53:53 · 4829 阅读 · 0 评论 -
Python heapq堆的常用方法
Python heapq堆的常用方法heapq.heappush(heap, item)heapq.heapify(list)heapq.heappop(heap)heapq.heapreplace(heap.item)heapq.heappushpop(list, item) heapq.heappush(heap, item) heap为定义堆,item增加的元素 >>> import heapq >>> h = [] >>> heapq.heapp原创 2020-05-14 20:52:53 · 489 阅读 · 0 评论 -
module 'itertools' has no attribute 'izip_longest'
将 itertools.izip_longest(S, T) 改为 zip_longest(S, T) 原因: izip()和izip_longest()是属于itertools库的一个函数,在Python3中已经取消,具体分析如下: https://blog.youkuaiyun.com/sinat_28576553/article/details/85136614原创 2020-05-14 15:12:15 · 893 阅读 · 0 评论
分享