小编Thi*_*low的帖子

如何将多个列表附加到python字典中的一个键?

我想将值附加到字典中的键,其中值实际上是列表.可能有一个列表,或者可能有多个列表.

我正在尝试这样做的当前方式,我尝试添加的新列表只是覆盖了最后一个列表.据我所知,我不能将列表附加到这样的字典:

my_dict.append(my_list))
Run Code Online (Sandbox Code Playgroud)

当前代码互相覆盖:

urls[domain] = [uri, datecreated]
Run Code Online (Sandbox Code Playgroud)

这可能吗?如果是这样,怎么样?

示例结果如下所示

print all keys and values in urls{}:
google.com : ['/helloworld', 2010-04-02], ['/apage/anotherpage', 2015-09-12] 
microsoft.com : ['/awebpage', 2009-02-01], ['/bananas', 2015-12-24], ['/anothergreaturi', 205-12-10] 
Run Code Online (Sandbox Code Playgroud)

python dictionary list python-2.x python-2.7

2
推荐指数
1
解决办法
3841
查看次数

标签 统计

dictionary ×1

list ×1

python ×1

python-2.7 ×1

python-2.x ×1