所以我有这样一个列表:
['One', 'Two', 'Three', 'Four']
['Five', 'Six', 'Seven']
所以,一个包含两个元素的列表
lst = [['One', 'Two', 'Three', 'Four'], ['Five', 'Six', 'Seven']]
我还有一本字典,我这样声明:
numberDict = dict()
numberDict["One"] = "First"
numberDict["Two"] = "Second"
numberDict["Three"] = "Third"
numberDict["Four"] = "Fourth"
numberDict["Five"] = "Fifth"
numberDict["Six"] = "Sixth"
numberDict["Seven"] = "Seventh"
我的问题是:怎样才能让我的列表看起来像这样?用字典中的值替换它的值
lst = [['First', 'Second', 'Third', 'Fourth'], ['Fifth', 'Sixth', 'Seventh']]
使用列表理解:
另一方面,请注意,您还可以一次性初始化
numbersDict
相关问题 更多 >
编程相关推荐