GuyLivingUnderARock
GuyLivingUnderARock

Reputation: 3

Python: repeat sequence in function call

I'm sorry if the naming of this question isn't good or correct

I don't know if this is even possible, or if there is an easy way to do this

function( > x[0] * y[0] + < repeat this sequence for the length of x z)

Upvotes: 0

Views: 47

Answers (1)

Mike67
Mike67

Reputation: 11342

List comprehension may be what you're looking for. Use zip to merge the lists.

xlst = [1,2,3,4,5]
ylst = [5,4,3,2,1]

total = sum([x*y for x,y in zip(xlst,ylst)])  # 35

Upvotes: 1

Related Questions