如何更改Python字典中的键?
例程返回字典.除了需要重命名几个键之外,字典的一切都还可以.下面的代码将字典条目(key = value)复制到具有所需密钥的新条目中,然后删除旧条目.是否有更多的Pythonic方式,也许没有重复价值?
my_dict = some_library.some_method(scan)
my_dict['qVec'] = my_dict['Q']
my_dict['rVec'] = my_dict['R']
del my_dict['Q'], my_dict['R']
return my_dict
Run Code Online (Sandbox Code Playgroud) 有没有办法在重组文本中将长列表分成多列?
来源:
* a
* b
* c
* d
* e
* a
* c
* a
* d
* e
* f
Run Code Online (Sandbox Code Playgroud)
结果:
* a * e * d
* b * a * e
* c * c * f
* d * a
Run Code Online (Sandbox Code Playgroud)
目标是在 reST 指令中提供源列表,而不是使用某种其他语言来读取源列表,然后在 reST 中使用“.. raw::”指令写入结果文本。例如这个假设list-multicol指令:
.. list-multicol::
:columns: 3
* a
* b
* c
* d
* e
* a
* c
* a
* d
* e
* …Run Code Online (Sandbox Code Playgroud)