Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

recursive to imperatif

Name: Anonymous 2010-10-11 8:55

I dont understand how to turn recursive algorythm into imperatif one.

Can /prog/ give me an exemple on this:
taking a list and generate all combinaison without double:

def foo(cdr):
    if cdr == []: return ['']
    solution = ['']
    for car in cdr:
        tmp = list(cdr)
        tmp.remove(car)
        solution += [car + x for x in compose_me(tmp)]
    return solution

>>> foo(['1', '2', '3'])
['', '1', '12', '123', '13', '132', '2', '21', '213', '23', '231', '3', '31', '312', '32', '321']

Name: Anonymous 2010-10-12 5:48

COOL FREE PUBLIC WIFI

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List