kaw*_*awa 2 python merge dictionary
对 python 来说相当陌生,所以这可能看起来很菜鸟。我创建了两个 .line 格式的基本地图(对我来说是新的),每个地图都使用 matplotlib 显示不同的功能。这些地图是从单独的形状文件转换而来的。现在我需要将这两个 .line 地图合并为一个。
任何想法将不胜感激。TY。
小智 7
在Python 3.5或更高版本中:
z = {**x, **y}
Run Code Online (Sandbox Code Playgroud)
在Python 2(或 3.4 或更低版本)中编写一个函数:
def merge_two_dicts(x, y):
z = x.copy() # start with x's keys and values
z.update(y) # modifies z with y's keys and values & returns None
return z
z = merge_two_dicts(x, y)
Run Code Online (Sandbox Code Playgroud)