gpt4 book ai didi

dictionary - Tcl:字典里面的字典

转载 作者:行者123 更新时间:2023-12-03 00:10:00 26 4
gpt4 key购买 nike

我似乎无法将吉姆和鲍勃放入名为“鸡”的列表中。我知道这是可能的,可以在另一个具有值列表的字典中拥有一个字典。我究竟做错了什么?

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

如您所见,工具列表有效。但鸡肉 list 不起作用。我构建代码的方式有问题吗?我使用 dict lappend 还是 dict 出错了?任何事情都有助于阐明这一点,谢谢。

最佳答案

所以我去了 tcl 聊天室,他们告诉我:

如手册页中所述,dict 将 Chicken 和 Bob 都添加到 dict element Animal 中的列表中。

您不能直接附加到字典更深的列表中。

一种方法是:

dict with farm {
dict lappend animal chicken Jim Bob
}

所以是的,我的错。 :P 所有功劳都归功于 tcl 聊天室中的“schelte”。

额外: dict lappend 如此工作的原因来自 Donal Fellows 本人在上面的评论中,谢谢 Donal

关于dictionary - Tcl:字典里面的字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19281317/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com