如何在Python中比较多个数组

2024-12-12 23:50:19
推荐回答(1个)
回答1:

>>> x=range(1,10)
>>> x
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> sum([ i*i for i in x])
285
>>> y=range(10,1,-1)
>>> y
[10, 9, 8, 7, 6, 5, 4, 3, 2]
>>> [x[i]*y[i] for i in range(0,9)]
[10, 18, 24, 28, 30, 30, 28, 24, 18]