7.此函数只接收一个参数且此参数必须是列表数据类型,此函数完成的功能是返回给调用者一个字典,此字典的键值对为此列表的索引及对应的元素。例如传入的列表为:[11,22,33] 返回的字典为 {0:11,1:22,2:33}。
l2 = [11,22,33] def func8(l1): dic = {} for i in range(len(l1)): dic[i] = l1[i] return dic print(func8(l2))
l2 = [11,22,33] def func(lst): dic = {} for i,j in enumerate(l2,0): dic[i] = j return dic print(func(l2))
原文地址:https://www.cnblogs.com/apollo1616/p/9460509.html
时间: 2024-11-08 22:43:58