这就是场景的样子:我试图从一个列表中获取最大元素,基于另一个元素,该元素基本上表示我需要搜索的元素中的索引。的长度foo
可以改变。但测试的长度不会改变。
>>> test = [1,2,3,4,5,6,7,8]
>>> foo = [1,4]
>>> print max(test[foo[1]])
这有效..
但是,当我试图做
>>> print max(test[foo])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: list indices must be integers, not list
有没有其他方法,或者我应该参考另一个模块?如果是的话,请你给我推荐一下。