我正在尝试将[[“bill”,21],[“kevin”,42],[“gail”,20]格式的列表更改为格式{“bill”:21,“kevin”的字典“:42,”gail“:20}.是否有捷径可寻? 最佳答案
In [2]: l = [['bill', 21], ['kevin', 42], ['gail',20]]
In [3]: d = dict(l)
In [4]: d
Out[4]: {'gail': 20, 'bill': 21, 'kevin': 42}
我正在尝试将[[“bill”,21],[“kevin”,42],[“gail”,20]格式的列表更改为格式{“bill”:21,“kevin”的字典“:42,”gail“:20}.是否有捷径可寻? 最佳答案
In [2]: l = [['bill', 21], ['kevin', 42], ['gail',20]]
In [3]: d = dict(l)
In [4]: d
Out[4]: {'gail': 20, 'bill': 21, 'kevin': 42}