字典 [英] Dictionaries

查看:78
本文介绍了字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将两个词典添加到一个?

例如

a = {''a:1}

b = {''b '':2}


我需要


结果{'''':1,''b'':2} 。


有可能吗?


谢谢

L.

How can I add two dictionaries into one?
E.g.
a={''a:1}
b={''b'':2}

I need

the result {''a'':1,''b'':2}.

Is it possible?

Thank you
L.

推荐答案

2006年10月18日08:24:27 -0700,Lad< py **** @ hope.czwrote:
On 18 Oct 2006 08:24:27 -0700, Lad <py****@hope.czwrote:

如何将两个词典添加到一个?

例如

a = {''a:1}

b = {''b'':2}


我需要


结果{'''':1,''b' :2}。
How can I add two dictionaries into one?
E.g.
a={''a:1}
b={''b'':2}

I need

the result {''a'':1,''b'':2}.


>> a = {''a'':1 }
b = {''b'':2}
a.update(b)
a
>>a={''a'':1}
b={''b'':2}
a.update(b)
a



{''a'':1,''b'':2}


-

干杯,

Simon B
si***@brunningonline.net
http://www.brunningonline.net/simon/blog/


Lad写道:
Lad wrote:

如何将两个词典添加到一个?

例如

a = {''a:1}

b = {''b'':2}


我需要


结果{'''':1,''b'':2}。


有可能吗?


谢谢

L.

How can I add two dictionaries into one?
E.g.
a={''a:1}
b={''b'':2}

I need

the result {''a'':1,''b'':2}.

Is it possible?

Thank you
L.



是的,使用更新。请注意,这会修改一个字典,而不是返回一个新字典。

Yes, use update. Beware that this modifies a dictionary in place rather
than returning a new dictionary.


>> a = {'''':1}
b = {''b'':2}
a.update(b)
a
>>a={''a'':1}
b={''b'':2}
a.update(b)
a



{''''':1,''b'':2}


Gary Herron

{''a'': 1, ''b'': 2}

Gary Herron


如何将两个词典添加到一个词典中?
How can I add two dictionaries into one?

例如

a = {''a:1}

b = {''b'':2我需要


结果{'''':1,''b'':2}。
E.g.
a={''a:1}
b={''b'':2}

I need

the result {''a'':1,''b'':2}.


>> a.update(b)
a
>>a.update(b)
a



{''a'':1,''b'':2}


-tkc

{''a'':1,''b'':2}

-tkc


这篇关于字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆