map()函数

来源:互联网 发布:汽车刷ecu软件 编辑:程序博客网 时间:2024/06/06 00:12

map(a,b)-第一个参数是函数名,第二个参数是可迭代对象
for example:

from itertools import permutations list1 = 'abc'list2 = []print(sorted(list(set(map(''.join,permutations(list1))))))

输出结果

['abc', 'acb', 'bac', 'bca', 'cab', 'cba']
list2 = []list1 = 'abc'iter = itertools.permutations(list1)print(sorted(list(set(map(''.join,itertools.permutations(list1))))))list2.append(list(iter))print(list2)
['abc', 'acb', 'bac', 'bca', 'cab', 'cba'][[('a', 'b', 'c'), ('a', 'c', 'b'), ('b', 'a', 'c'), ('b', 'c', 'a'), ('c', 'a', 'b'), ('c', 'b', 'a')]]

可以看出map()函数,就是将后面的可迭代对像,经过前面定义的函数操作,把所有元素join一起,成了第一种结果,

原创粉丝点击