随笔分类 - Python
摘要:bisect — Array bisection algorithm This module provides support for maintaining a list in sorted order without having to sort the list after each inse
阅读全文
摘要:Python中的deque(Doubly Ended Queue)是使用collections模块实现的。 在我们需要从容器的两端更快地执行append和pop操作的情况下,与列表相比,使用双端队列更可取,因为与O(n)时间复杂度的列表相比,双端队列为append和pop操作提供了O(1)时间复杂度
阅读全文
摘要:Example Check if any of the items in a list are True: mylist = [False, True, False]x = any(mylist) True Definition and Usage The any() function return
阅读全文
摘要:Check if all items in a list are True: Definition and Usage The all() function returns True if all items in an iterable are true, otherwise it returns
阅读全文
摘要:发现不是很清楚,遂整理StackOverflow如下 Generally, you want to use the built-in sorted() function which takes a custom comparator as its parameter. We need to pay
阅读全文
摘要:Permutation First import itertools package to implement permutations method in python. This method takes a list as an input and return an object list
阅读全文
摘要:Binary Search 是一种用于搜索排序列表中元素的technique。在本文中,我们将研究执行Binary Search 的库函数。 Finding first occurrence of an element. bisect.bisect_left(a, x, lo=0, hi=len(a
阅读全文
摘要:https://stackoverflow.com/questions/231767/what-does-the-yield-keyword-do
阅读全文
摘要:zip() 函数用于将可迭代的对象作为参数,将对象中对应的元素打包成一个个元组,然后返回由这些元组组成的列表。 如果各个迭代器的元素个数不一致,则返回列表长度与最短的对象相同,利用 * 号操作符,可以将元组解压为列表。 Definition and Usage The zip() function
阅读全文
摘要:>>> import string >>> string.ascii_lowercase 'abcdefghijklmnopqrstuvwxyz' 用list >>> list(string.ascii_lowercase) ['a', 'b', 'c', 'd', 'e', 'f', 'g', '
阅读全文
摘要:↓ 2进制 8进制 10进制 16进制 2进制 - bin(int(x, 8)) bin(int(x, 10)) bin(int(x, 16)) 8进制 oct(int(x, 2)) - oct(int(x, 10)) oct(int(x, 16)) 10进制 int(x, 2) int(x, 8)
阅读全文
摘要:Defaultdict is a container like dictionaries present in the module collections. Defaultdict is a sub-class of the dict class that returns a dictionary
阅读全文
摘要:Python 字典(Dictionary) items() 函数以列表返回可遍历的(键, 值) 元组数组。 Example #1: # Python program to show working # of items() method in Dictionary # Dictionary with
阅读全文
摘要:#交集a = [1,2,3,4] b = [2,4,5,5,7] intersection = list(set(a) & set(b)) >>[2,4] #并集a = [1,2,3] b = [5,7,3] unionset = list(set(a).union(set(b))) >>[1,2,
阅读全文
摘要:enumerate() 函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列,同时列出数据和数据下标,一般用在 for 循环当中。 Python 2.3. 以上版本可用,2.6 添加 start 参数。 Syntax: enumerate(iterable, start=0) P
阅读全文
摘要:Python – Itertools Combinations() function Itertool is a module of Python which is used to creation of iterators which helps us in efficient looping i
阅读全文
摘要:str.format() is one of the string formatting methods in Python3, which allows multiple substitutions and value formatting. This method lets us concate
阅读全文
摘要:The divmod() method takes two numbers and returns a pair of numbers (a tuple) consisting of their quotient and remainder. The syntax of divmod() is: d
阅读全文
摘要:class collections.Counter([iterable-or-mapping]) A Counter is a dict subclass for counting hashable objects. It is an unordered collection where eleme
阅读全文
摘要:Description The reduce(fun,seq) function is used to apply a particular function passed in its argument to all of the list elements mentioned in the se
阅读全文

浙公网安备 33010602011771号