如何使用 Python 获取列表列表中最大列表的索引?
我将 Cinema4D 中的动画关键帧(使用很棒的 py4D)存储到列表列表中:
props = [lx,ly,lz,sx,sy,sz,rx,ry,rz]
我打印出了任意动画中每个属性/轨道的关键帧,它们的长度不同:
track Position . X has 24 keys
track Position . Y has 24 keys
track Position . Z has 24 keys
track Scale . X has 1 keys
track Scale . Y has 1 keys
track Scale . Z has 1 keys
track Rotation . H has 23 keys
track Rotation . P has 24 keys
track Rotation . B has 24 keys
现在,如果我想在搅拌机我需要做类似的事情:
- 转到当前帧
- 设置该关键帧的属性(可以是位置、旋转、缩放)并插入关键帧
到目前为止我的计划是:
- 从 0 循环到关键帧的最大数量对于所有属性
- 循环遍历每个属性
- 检查它是否为当前键存储了值,如果是,则转到 Blender 中的帧并存储值/插入关键帧
这是执行此操作的最佳方法吗?
这是问题的背景。
首先我需要找到道具存储的最大列表。我是 python 新手,想知道是否有一个神奇的函数可以为你做到这一点。与 max() 类似,但用于列表长度。
目前我正在考虑这样编码:
# after props are set
lens = []
for p in props: lens.append(len(p))
maxLen = max(lens)
实现这一目标的最佳方法是什么?
谢谢
I am storing animation key frames from Cinema4D(using the awesome py4D) into a lists of lists:
props = [lx,ly,lz,sx,sy,sz,rx,ry,rz]
I printed out the keyframes for each property/track in an arbitrary animation and they are of different lengths:
track Position . X has 24 keys
track Position . Y has 24 keys
track Position . Z has 24 keys
track Scale . X has 1 keys
track Scale . Y has 1 keys
track Scale . Z has 1 keys
track Rotation . H has 23 keys
track Rotation . P has 24 keys
track Rotation . B has 24 keys
Now if I want to use those keys in Blender I need to do something like:
- go to the current frame
- set the properties for that key frame( can be location,rotation,scale) and insert a keyframe
So far my plan is to:
- Loop from 0 to the maximum number of key frames for all the properties
- Loop through each property
- Check if it has a value stored for the current key, if so, go to the frame in Blender and store the values/insert keyframe
Is this the best way to do this ?
This is the context for the question.
First I need to find the largest list that props stores. I'm new to python and was wondering if there was a magic function that does that for you. Similar to max(), but for list lengths.
At the moment I'm thinking of coding it like this:
# after props are set
lens = []
for p in props: lens.append(len(p))
maxLen = max(lens)
What would be the best way to get that ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这将为您提供一个包含 props 中最长列表的
(index, list)
的元组。This gives you a tuple containing
(index, list)
of the longest list in props.您可以使用生成器表达式:
You can use a generator expression: