我有一个列表,我想将此列表转换为地图
mylist = ["a",1,"b",2,"c",3]
mylist 相当于
mylist = [Key,Value,Key,Value,Key,Value]
所以输入:
mylist = ["a",1,"b",2,"c",3]
输出:
mymap = {"a":1,"b":2,"c":3}
PS:我已经写了下面的函数做同样的工作,但我想使用 python 的迭代器工具:
def fun():
mylist = ["a",1,"b",2,"c",3]
mymap={}
count = 0
for value in mylist:
if not count%2:
mymap[value] = mylist[count+1]
count = count+1
return mymap