dictionary - TCL 多级字典 - 如何通过附加到相同的键来更新它

标签 dictionary tcl

我有一个名为 test 的字典,我希望通过向其附加新项目来迭代更新相同的键。所以最终它看​​起来像这样

目标

test {
1 {flps {o1 o2 o3 ...}}
}

执行此操作的标准方法是什么?我现在有以下代码:

set test [dict create] ;
dict set test 1 "flps" "o1"   ;  #### first value o1 added
set new "[dict get $test 1 regs] o2" ; ##temp variable that append the old + new value
dict set test 1 regs $new         ; ### does dict set overwrite ? 

最佳答案

What is the standard way to do this ?

没有用于此目的的内置命令,一种方法是使用dict update:

% set test [dict create]
% dict update test 1 1 { dict lappend 1 flps "o1" }
flps o1
% set test
1 {flps o1}
% dict update test 1 1 { dict lappend 1 flps "o2" }
flps {o1 o2}
% set test
1 {flps {o1 o2}}

但是,当嵌套级别更多或什至未知的嵌套深度时,这很容易变得不方便。

关于dictionary - TCL 多级字典 - 如何通过附加到相同的键来更新它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60511490/

相关文章:

c# - 将字典序列化到磁盘?

python - 使用 For 循环修改 Pandas 中的 DataFrame 字典

ubuntu - 无法在 mint 上构建 tdbc 1.0.6

multithreading - Tcl的线程安全记录器

namespaces - TCL 全局 vs. 可变访问速度

sqlite - U2宇宙: update a multivalue field

linux - 将 puts 的输出同时发送到日志文件和标准输出?

python - 迭代字典和列表的字典的 Pythonic 方法是什么?

python - 从字典中调用函数

从嵌套字典中调用特定键/值的Pythonic方式