美文网首页
Python函数(个人笔记)

Python函数(个人笔记)

作者: 你旭哥 | 来源:发表于2018-03-12 00:20 被阅读0次

lambda用法

将函数转化为表达式

g = lambda x:x+1

def g(x):
    return x+1

map用法

 proxys = list(map(lambda x: x.strip(), [y for y in lines]))

set()集合

set() 函数创建一个无序不重复元素集;可进行关系测试,删除重复数据,还可以计算交集、差集、并集等。

将序列转化为set

crawl_ID = set([list])

交集并集差集

>>> x & y         # 交集
set(['o'])
>>> x | y         # 并集
set(['b', 'e', 'g', 'l', 'o', 'n', 'r', 'u'])
>>> x - y         # 差集
set(['r', 'b', 'u', 'n'])

成员关系

if ID not in self.temp_ID:
    self.temp_id_process(ID)

if ID not in self.finish_ID:
    self.crawl_ID.add(ID)

相关文章

网友评论

      本文标题:Python函数(个人笔记)

      本文链接:https://www.haomeiwen.com/subject/zzzifftx.html