Python Forum

Full Version: HELP ME
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I wrote the code, but each digit with 3 digits could not reflect a different 4 permutation please help.

def comb(L): 
      
    for i in range(3): 
        for j in range(3): 
            for k in range(3): 
                  
              
                if (i!=j and j!=k and i!=k): 
                    print(L[i], L[j], L[k]) 
                      

comb([1, 2, 3, 4])
try:
def comb(l):
    size = len(l)
    for i in range(size):
        for j in range(size):
            for k in range(size):
                if i != j and j != k and i != k:
                    print(l[i], l[j], l[k])


comb([1, 2, 3, 4])
I would expect a function named "comb" to generate combination. Superjoe's code, and the code it looks like you are trying to write, make some kind of weird permutation where the values for each entry must be unique. Is that what you were trying to do?

If you need combinations or permutations for an assignment I suggest using the functions in the itertools standard library. Unless, of course, your assignment is to write a combinations function.