I'm having some issues. I'm learning about dynamic pgrogramming and want to create a function getContWordPermutation(str) that finds all continues substring permutations. for example:
>>>getContWordPermutation('abc')
['abc', 'bc', 'c', 'b', 'ac', 'a', 'ab']
my code runs perfectly once.
def getContWordPermutation(word,m=[]):
if word == '':
return
if word not in m:
m.append(word)
for i in range(0,len(word)):
newWord = word[0:i]+word[i+1:]
if word not in m:
m.append(word[:-i])
getContWordPermutation(newWord)
return m
this runs perfectly as according to my example. But somehow this list m lives globally, because next call of function is being affacted of first call
>>>getContWordPermutation('abc')
>>>getContWordPermutation('de')
['abc', 'bc', 'c', 'b', 'ac', 'a', 'ab', 'de', 'e', 'd']
please help me understand, i'm going nuts