包含列表的字典 [英] dictionary containing a list

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

问题描述

您好...


我已经设置了一个字典,其中列出了我的列表值。我每次用新值填充我的列表周围和周围的
然后

将此列表转储到字典中。或者我认为...


看起来我倾向于字典值的是

只是指向原始列表的指针,所以之后我所有的迭代都是我的b $ b有一本字典,其每一个值都等于最后一次循环的列表的值:-(


有没有办法实现我的尝试?我做了一些事情

几乎与之前列表中的类相同,在这种情况下是新的

实例是为每个列表条目创建的......

我希望这有一定道理,并且似乎没什么好听的。

简单...

干杯,


Ben

Hello...

I have set up a dictionary into whose values I am putting a list. I
loop around and around filling my list each time with new values, then
dumping this list into the dictionary. Or so I thought...

It would appear that what I am dumping into the dictionary value is
only a pointer to the original list, so after all my iterations all I
have is a dictionary whose every value is equal to that of the list the
final time I looped around :-(

Is there a way to acheive what I was attempting ? I have done something
almost identical with classes in a list before, and in that case a new
instance was created for each list entry...
I hope this makes some sense, and doesn''t seem to head bangingly
simple...
Cheers,

Ben

推荐答案



Ben写道:

Ben wrote:

你好......


我已经设置了一个字典,我的价值观是我的放一个清单。我每次用新值循环填充我的清单,然后


将此列表转储到字典中。或者我认为...


看起来我倾向于字典值的是

只是指向原始列表的指针,所以之后我所有的迭代都是我的b $ b有一本字典,其每一个值都等于最后一次循环的列表的值:-(


有没有办法实现我的尝试?我做了一些事情

几乎与之前列表中的类相同,在这种情况下是新的
$ b为每个列表条目创建了$ b实例...


我希望这有一定道理,而且似乎没什么可回头的。简单地说b
。 ..
Hello...

I have set up a dictionary into whose values I am putting a list. I
loop around and around filling my list each time with new values, then
dumping this list into the dictionary. Or so I thought...

It would appear that what I am dumping into the dictionary value is
only a pointer to the original list, so after all my iterations all I
have is a dictionary whose every value is equal to that of the list the
final time I looped around :-(

Is there a way to acheive what I was attempting ? I have done something
almost identical with classes in a list before, and in that case a new
instance was created for each list entry...
I hope this makes some sense, and doesn''t seem to head bangingly
simple...



您是否通过视频链接咨询您的医生,同时在午夜时分在一个未点燃的煤矿上穿着忍者

服装? />

请考虑您对代码可能做的内容的描述可能不足以诊断。


您可能需要提供:
(1)您的代码清单

(2)少量输入数据

例如[(1,''foo''),(42,''bar''),(1,''zot'')]

(3)您对该输入的期望输出:

例如{1:[''foo'',''zot''],42:[''bar'']}


干杯,

John

Do you consult your physician over a video link while wearing a ninja
costume down an unlit coal mine at midnight?

Please consider the possibility that your description of what you think
your code might be doing is not enough for diagnosis.

You may need to supply:
(1) a listing of your code
(2) a small amount of input data
e.g. [(1, ''foo''), (42, ''bar''), (1, ''zot'')]
(3) the output you expect from that input:
e.g. {1: [''foo'', ''zot''], 42: [''bar'']}

Cheers,
John


" Ben" <是************* @ gmail.comwrites:
"Ben" <Be*************@gmail.comwrites:

我已经设置了一个字典,我将它的值放入其中名单。我每次用新值填充我的列表周围和周围的
循环,然后将这个列表转储到字典中。或者我认为...
I have set up a dictionary into whose values I am putting a list. I
loop around and around filling my list each time with new values,
then dumping this list into the dictionary. Or so I thought...



我们的水晶球因查看程序代码而闻名不可靠

尚未发布。


-

\对于男人来说,至于花兽兽,至高无上的胜利|

` \\ \\是最生动,最完美的生活 - D.H.劳伦斯。 |

_o__)|

Ben Finney

Our crystal balls are notoriously unreliable for viewing program code
that hasn''t been posted.

--
\ "For man, as for flower and beast and bird, the supreme triumph |
`\ is to be most vividly, most perfectly alive" -- D.H. Lawrence. |
_o__) |
Ben Finney


Ben写道:
Ben wrote:

我已经设置了一个字典到我的列表中的值。我每次用新值填充我的列表周围和周围的
然后

将此列表转储到字典中。或者我认为...


看起来我倾向于字典值的是

只是指向原始列表的指针,所以之后我所有的迭代都是我的b $ b有一本字典,其每一个值都等于最后一次循环的列表的值:-(


有没有办法实现我的尝试?
I have set up a dictionary into whose values I am putting a list. I
loop around and around filling my list each time with new values, then
dumping this list into the dictionary. Or so I thought...

It would appear that what I am dumping into the dictionary value is
only a pointer to the original list, so after all my iterations all I
have is a dictionary whose every value is equal to that of the list the
final time I looped around :-(

Is there a way to acheive what I was attempting ?



如果你循环...填写[你的]清单,请使用每次新的

列表。您可以使用[]创建一个新的空列表。


-

--Bryan

Where you "loop around ... filling [your] list", use a new
list every time. You can create a new empty list with "[]".

--
--Bryan


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

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