Debugging reason for python running unreasonably slow when adding numbers
David Raymond
David.Raymond at tomtom.com
Wed Mar 15 11:44:47 EDT 2023
> Then I'm very confused as to how things are being done, so I will shut
> up. There's not enough information here to give performance advice
> without actually being a subject-matter expert already.
Short version: In this specific case "weights" is a 5,147 element list of floats, and "input" is a 10 element list of integers which has the indexes of the 10 elements in weights that he wants to add up.
sum_ = 0
for key in input:
sum_ += weights[key]
vs
sum_ = sum(weights[key] for key in input)
vs... other ways
More information about the Python-list
mailing list