- List.extend:
extend() 函数用于在列表末尾一次性追加另一个序列中的多个值(用新列表扩展原来的列表)。
aList = [123, 'xyz', 'zara', 'abc', 123];
bList = [2009, 'manni'];
aList.extend(bList)
print "Extended List : ", aList ;
输出
Extended List : [123, 'xyz', 'zara', 'abc', 123, 2009, 'manni']
2.collections.Counter()
Counter是一个简单的计数器,例如,统计字符出现的个数:
>>> from collections import Counter
>>> c = Counter()
>>> for ch in 'programming':
... c[ch] = c[ch] + 1
...
>>> c
Counter({'g': 2, 'm': 2, 'r': 2, 'a': 1, 'i': 1, 'o': 1, 'n': 1, 'p': 1})
3.collections.Counter().most_common([:n-1])
取出计数最多的n个数
4.zip(dictionary.values(), dictionary.keys())
保存为二元组
5.raise NotImplementedError(“Each Model must re-implement this method.”)
未实现接口会弹出错误
6.Python class中的_ cal l_()方法
class Hello_world(object):
def __call__(self, string):
print "Hello ", string
if __name__ = main:
h = Hello_world()
h("world")
>> Hello world
7.判断两个列表是否相等numpy.allclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)
如果两个列表各元素的差值都在一定的容忍度内相等,则返回True()
if the following equation is element-wise True, then allclose returns True.
absolute(a - b) <= (atol + rtol * absolute(b))