I need to find all the "a" and "b" values for a Pythagorean triple. For example, I would specify the number as a parameter and find all the Pythagorean triples for it. Here is some example code that my teacher gave me:
>>> pytriples(5)
>>> [3,4,5] #would return this
>>> pytriples(25)
>>> [7,24,25] #would return this
>>> [15,20,25] #would return this
Basically, I need to write the pytriples program and I get full marks for not having repeats of "a" and "b". This is what I have developed - the problem is, I do not have any way to remove the duplicates.
This is what I have:
def pytriples(c):
newlist = []
for a in range(0, c):
if ((c**2 - a**2)**0.5)%1 == 0:
b = ((c**2 - a**2)**0.5)
newlist.append([a,b,c])
for i in newlist: #this part is supposed to remove the duplicates
print i[0] #was used for debugging but I could not figure out why duplicates were not removed
if i[0] >= i[1]:
newlist.remove(i)
return newlist