[英]add an item into sublist as value inside a dictionary
I suppose this could be easy, but I could not find how to do it. 我想这可能很容易,但是我找不到如何做。 If I have a dictionary d:
d = {1: [4,3], 5:[6,7,8]}
如果我有字典d:
d = {1: [4,3], 5:[6,7,8]}
How can I add another value (ex. 2) to the sublist [4, 3], to obtain this: d = {1: [4,3,2], 5:[6,7,8]}
如何将另一个值(例如2)添加到子列表[4,3]中以获得此值:
d = {1: [4,3,2], 5:[6,7,8]}
Simple. 简单。
d = {1: [4,3], 5: [6,7,8]}
d[1].append(2)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.