Stackless Python - Recursion in a for loop?

I am new to programming and have been working with Python for several months now. I am trying to get a concept for working with Stackless, but I just can't figure out how (although I wrote other test scripts that work with Stackless).

Anywho, as the example examined, will consider the following code that goes through the list and finds all permutations (edit: n-dimensional Cartesian products), calling the same function recursively.

def traverseList(theList,temp,solutions,level=1):
    if level != len(theList):
        for x in theList:
            temp.append(x)
            traverseList(theList,temp,solutions,level+1)
            temp.pop()
    else:
        for x in theList:
            temp.append(x)
            solutions.append(temp[:])
            temp.pop()

myList = ["a",None,2,"gamma",8] #the list doesn't always have just numbers
solutionList = []
tempList = []

traverseList(myList,tempList,solutionList)
print("%s... %s" %(solutionList[0], solutionList[-1]))

which gives:

['a', 'a', 'a', 'a', 'a']... [8, 8, 8, 8, 8]

It still seems that the only examples that I find in Stackless and recursion have a function to send information at the end of a function after it is completed. Never in the middle of a for loop, as would be necessary in the above.

? script, , ? ( - , , , . , .)

e-cookie , bounceBack - .

!

+3
2

, "" (.. "" python). . "" , "". , , "", .

:

def myGen(*x):
  for elem in x:
    print "in myGen"
    yield elem

def myFn(*x):
  ret = []
  for elem in x:
    print "in myFn"
    ret.append(x)
  return x


for e in myGen(1,2,3,4,5):
  print e

for e in myFn(1,2,3,4,5):
  print e

. , (myGen) "in myGen", . myFn, , "in myFn".

in myGen
1
in myGen
2
in myGen
3
in myGen
4
in myGen
5
in myFn
in myFn
in myFn
in myFn
in myFn
1
2
3
4
5
+1

, ,

import stackless as s
channel = s.channel()
s.tasklet(traverseList)(myList,tempList,solutionList)
s.run()
print("%s... %s" %(solutionList[0], solutionList[-1]))

* args/** kwargs

0
source

All Articles