0
考慮我有在Python對於每一個列表的Python
numbers = (('One', 1), ('Two', 2), ('Three', 3), ('Four', 4))
一個元組,我想創建在字典中的numbers_dict
numbers_dict = {}
for number in numbers:
numbers_dict[number[0]] = number[1]
,所以我得到
numbers_dict = {
'One': 1,
'Two': 2,
'Three': 3,
'Four': 4,
}
我可以使用語法更簡單些
numbers_dict = [n[0] : n[1] for n in numbers]
?