Flatten a multi |
def flattenList2 ( head ) : NEW_LINE INDENT headcop = head NEW_LINE save = [ ] NEW_LINE save . append ( head ) NEW_LINE prev = None NEW_LINE while ( len ( save ) != 0 ) : NEW_LINE INDENT temp = save [ - 1 ] NEW_LINE save . pop ( ) NEW_LINE if ( temp . next ) : NEW_LINE INDENT save . append ( temp . next ) NEW_LINE DEDENT if ( temp . down ) : NEW_LINE INDENT save . append ( temp . down ) NEW_LINE DEDENT if ( prev != None ) : NEW_LINE INDENT prev . next = temp NEW_LINE DEDENT prev = temp NEW_LINE DEDENT return headcop NEW_LINE DEDENT