I'm trying to calculate the following double sum which calculates the chance of someone finishes 2nd in some sort of race given we have the chance of the individual finishes 1st. X being the length of the list of runners and also n!=i
The following code does the work
def Scnd(mylist=[]):
sec=[]
for seconds in range(len(mylist)):
sum=0
for firsts in range(len(mylist)):
if firsts==seconds:
pass
else:
sum_second=mylist[firsts]*(mylist[seconds]/(1-mylist[firsts]))
sum+=sum_second
sec.append(sum)
print(sec)
#do something with the list
with the following example
alist=[0.4,0.25,0.2,0.15]
Scnd(alist)
the result will be
[0.303921568627451, 0.2732843137254902, 0.23529411764705882, 0.1875]
I understand this code is really slow and I'm wondering about ways to make it faster (possibly a lot neater in the process too).