0

I have two lists:

  1. with the elements: [0.7181,7.3,561257621.7,0.12122,9.8]
  2. with indices:[0,2]

How can I calculate average of elements which indices I do have in second table?

MaxU - stand with Ukraine
  • 205,989
  • 36
  • 386
  • 419
donchuan
  • 85
  • 1
  • 10

1 Answers1

2

I would use:

>>> elements = [0.7181, 7.3, 561257621.7, 0.12122, 9.8]
>>> indices = [0, 2]
>>> sum([elements[i] for i in indices])/len(indices)
280628811.20905
Simpom
  • 938
  • 1
  • 6
  • 23