gpt4 book ai didi

python - 执行以下枚举的更整洁、更 pythonic 的方法是什么?

转载 作者:太空宇宙 更新时间:2023-11-04 09:21:37 29 4
gpt4 key购买 nike

for row, instrument in enumerate(instruments):
for col, value in enumerate(instrument):
self.table.SetValue(row, col, value)

最佳答案

你所说的 row 不是一行,它是行索引。 instrument 是一行。除此之外:

如果您拥有的唯一工具是 SetValue(row_index, column_index, value) 方法并且该方法不仅仅有助于复制工具的结构费力地,并且 instruments 集合正如您的代码所描述的那样,那么没有更好的方法了。已经比

#WARNING: BAD PRACTICE! DON'T USE THIS CODE!
for row_index in xrange(len(instruments)):
instrument = instruments[row_index]
for column_index in xrange(len(instrument)):
self.table.SetValue(row_index, column_index, instrument[column_index])

或其任何歪曲。

否则你可能对import copy感兴趣; self.table = copy.copy(instruments) 甚至(正如 SilentGhost 所建议的那样)self.table = instruments

关于python - 执行以下枚举的更整洁、更 pythonic 的方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1900195/

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