如何将python代码转换为列表理解?

如何将python代码转换为列表理解?,python,list,for-loop,list-comprehension,spyder,Python,List,For Loop,List Comprehension,Spyder,我被要求将这些行转换成一个列表 tmaxima = [] ag_maxima = [] for i in sorted_indices: tmaxima.append(t[i]) ag_maxima.append(a_g[i]) 假设排序后的索引只包含整数: tmaxima = [t[i] for i in sorted_indices] ag_maxima = [a_g[i] for i in sorted_indices] (1) 缩进在语法上无效。(2) 您将需要两个列表理解。(3)

我被要求将这些行转换成一个列表

tmaxima = []
ag_maxima = []
for i in sorted_indices:
tmaxima.append(t[i])
ag_maxima.append(a_g[i])

假设排序后的索引只包含整数:

tmaxima = [t[i] for i in sorted_indices]
ag_maxima = [a_g[i] for i in sorted_indices]
(1) 缩进在语法上无效。(2) 您将需要两个列表理解。(3) 展示您自己解决问题的努力和代码(如问题中正确格式化的文本)。