zip(iterable, ...)
其中 iterable,... 表示多个列表、元组、字典、集合、字符串,甚至还可以为 range() 区间。my_list = [11,12,13] my_tuple = (21,22,23) print([x for x in zip(my_list,my_tuple)]) my_dic = {31:2,32:4,33:5} my_set = {41,42,43,44} print([x for x in zip(my_dic)]) my_pychar = "python" my_shechar = "shell" print([x for x in zip(my_pychar,my_shechar)])程序执行结果为:
[(11, 21), (12, 22), (13, 23)]
[(31,), (32,), (33,)]
[('p', 's'), ('y', 'h'), ('t', 'e'), ('h', 'l'), ('o', 'l')]
my_list = [11,12,13] my_tuple = (21,22,23) print(list(zip(my_list,my_tuple)))程序执行结果为:
[(11, 21), (12, 22), (13, 23)]
本文链接:http://task.lmcjl.com/news/9492.html