J
J
JSent2018-04-10 12:56:07
Python
JSent, 2018-04-10 12:56:07

What is the correct way to pass a list to a Python function?

Wrote a function to compose all placements without repetition.

def combinator(setOfNum,length,deep=-1,arrayOfComb=[],num=[]):
  if deep == -1 : deep = length
  if deep == 0:
    arrayOfComb.append(copy.copy(num))
    return
  for i in range(setOfNum):
    if num.count(i) == 0: num.append(i)
    else: continue
    combinator(setOfNum,length,deep-1)
    del num[-1]
  if deep == length:
    return copy.copy(arrayOfComb)

The problem is that every time the function is called, the new result is added to the old one. Removing before return doesn't help. It seems to me that lists should be passed differently.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question