Python beginner, strange output problem

Posted by Protean on Stack Overflow See other posts from Stack Overflow or by Protean
Published on 2010-04-06T05:12:35Z Indexed on 2010/04/06 6:03 UTC
Read the original article Hit count: 293

Filed under:
|

I'm having a weird problem with the following piece of code.

from math import sqrt

def Permute(array):
    result1 = []
    result2 = []
    if len(array) <= 1:
        return array
    for subarray in Permute(array[1:]):
        for i in range(len(array)):
            temp1 = subarray[:i]+array[0]+subarray[i:]
            temp2 = [0]
            for num in range(len(array)-1):
                temp2[0] += (sqrt(pow((temp1[num+1][1][0]-temp1[num][1][0]),2) + pow((temp1[num+1][1][1]-temp1[num][1][1]),2)))
            result1.append(temp1+temp2)
    return result1

a = [['A',[50,1]]]
b = [['B',[1,1]]]
c = [['C',[100,1]]]
array = [a,b,c]

result1 = Permute(array)
for i in range(len(result1)):
    print (result1[i])
print (len(result1))

What it does is find all the permutations of the points abc and then returns them along with the sum of the distances between each ordered point. It does this; however, it also seems to report a strange additional value, 99. I figure that the 99 is coming from the computation of the distance between point a and c but I don't understand why it is appearing in the final output as it does.

© Stack Overflow or respective owner

Related posts about python

Related posts about beginner