s=[31, 18, 19, 1, 25] n=10 row,col=0,len(s)-1 max_size,all_size=0,0 while(col>0): i,j=row,col print(i,j) temp_len=0 while(i<len(s) and j<len(s)): if(abs(s[i]-s[j])<=n): max_size+=1 all_size+=1 i += 1 j += 1 if (col > 0): col -= 1 print('%.6f'%(max_size/all_size))