我似乎对把吉姆和鲍勃列入名为“鸡”的名单有意见。我知道这是可能的,在另一个字典中有一个字典,它有一个值列表。我做错了什么?
puts [dict set farm tools hoe]
puts [dict lappend farm tools pitchfork]
puts [dict set farm animal cow Marry]
puts [dict set farm animal chicken Jim]
puts [dict lappend farm animal chicken Bob]
puts "chicken list: [dict get $farm animal chicken]"
puts "tool list: [dict get $farm tools]"输出
tools hoe
tools {hoe pitchfork}
tools {hoe pitchfork} animal {cow Marry}
tools {hoe pitchfork} animal {cow Marry chicken Jim}
tools {hoe pitchfork} animal {cow Marry chicken Jim chicken Bob}
chicken list: Bob
tool list: hoe pitchfork如您所见,工具列表起作用了。但鸡肉清单不管用。我的代码结构有问题吗?我用的是丁丁,还是别搞错了?任何事情都能帮助我们了解这一点,谢谢。
发布于 2013-10-10 20:27:30
于是我去了tcl聊天室,他们告诉我:
正如手册页所描述的那样,dict将小鸡和Bob都添加到了dict元素动物的列表中。
你不能直接附加到更深层次的列表中。
一种办法是:
dict with farm {
dict lappend animal chicken Jim Bob
}所以你,我的错。P所有的功劳都归于tcl聊天室里的"schelte“。
额外:在上面的评论中,的工作方式是来自Donal Fellow本人的原因,谢谢Donal
https://stackoverflow.com/questions/19281317
复制相似问题