How to check if a list contains a group of values in any order - Python -


I am writing a program that takes a triangular number, and finds three other triangular numbers, whose sum is first At the same time, I have all the code currently given below if you run the program and type 10 instances for the input, then it will print a list of the first 10 triangular numbers, with the combination of small triangular numbers, whose sum is 10 We Is.

What I am trying to do, to prevent you from coming in a different order in the same order, if you use again 10 examples, then the output is:

21 + 28 + 6 = 55

28 + 21 + 6 = 55

6 + 21 + 28 = 55

21 + 28 + 6 = 55 < P>

45 + 10 = 55

but clearly 6 + 21 + 28 = 55 6 + 28 + 21 = 55 is equal to, 10 + 45 = 55 and 45 + 10 = 55 And likewise ... they are just in a different order, so does anyone know in a simple way that I can check to make sure Set of values ​​does not repeat in any order? If you still have a question that I am trying to do, then post a comment and explain it better.

code:

  def f (x): in category for newX = 0 (0, x): newX = newX + i NewX def main () Goes: lst = [] inpt = input ("What number of triangular numbers you want to test:") range (2, apt + 2): x = f (i) lst.append (x) (x, Lst) #x is a triangular number, the list is a list of all those that make it def (x, lst)): a = 0 b = 0 c = 0 length = len (lst) print (lst) last = lst [length - 1] for h for lst: a = j in l: b = k if (a + b == x): if (a! = B): lst: c = i print (str (a) + " + "+ Str (b) +" = "+ str (A + B + c == x): if (a! = B and a! = C and b! = C): print (str (a) + "+" + str (b) The main () <+ code> 

a hint

  gt; & Gt; [1, 2, 3] == [1, 3, 2] false & gt; & Gt; & Gt; Sorted ([1, 3, 2]) [1, 2, 3] & gt; & Gt; & Gt; [1, 2, 3] == is sorted ([1, 3, 2]) True  

Canonicalization is a process by which one-one for one set -An order has elements This makes the comparison between the different sequences of the same elements the same.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -