zip函数和sorted函数

###zip函数
如果处理两个列表的话就以列表的形式输出
比如
list_a = [1,2,3,4,5]
list_b = ['a','b','c','d','e']
list_c = zip(list_b,list_a)
输出结果为:[('a', 1), ('b', 2), ('c', 3), ('d', 4),('e',5)]
# 合并两个字符串,以字典类型输出
str_a = "123456"
str_b = "abcdef"
str_c = zip(str_a,str_b)
输出结果为:{1:'a',2:'b',3:'c',4:'d',5:'e',6:'f'}
# 使用zip()和sorted()对字典排序
dict_a = {'a': '4', 'b': '1', 'c': '3', 'd': '2'}
print("直接取字典最小值:", min(dict_a.items()))
print("直接对字典排序:", sorted(dict_a.items()))
 
list_temp = zip(dict_a.values(), dict_a.keys())
print("zip处理后的最小值:", min(list_temp))
 
list_temp = zip(dict_a.values(), dict_a.keys())
list_temp = sorted(list_temp)
print("zip处理后的排序:", list_temp)
print("zip处理后的最小两个:", list_temp[0:2])

结果为:
直接取字典最小值: ('a', '4')
直接对字典排序: [('a', '4'), ('b', '1'), ('c', '3'), ('d', '2')]
zip处理后的最小值: ('1', 'b')
zip处理后的排序: [('1', 'b'), ('2', 'd'), ('3', 'c'), ('4', 'a')]
zip处理后的最小两个: [('1', 'b'), ('2', 'd')]