Python常见函数总结

  1. 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))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值