[Tutor] recursion

Ben Finney ben+python at benfinney.id.au
Fri Feb 5 03:34:28 EST 2016


noopy via Tutor <tutor at python.org> writes:

> But when "for cc in permutations([])" yields an empty list, why does
> "for cc in permutations("Z")" then actually have an item so that
> "yield [items[i]]+cc" will be executed?

Does this help::

    >>> i = 1
    >>> "Z"[:i] + "Z"[i+1:]
    'Z'

Can you explain why that would be the case?

-- 
 \         “I think a good gift for the President would be a chocolate |
  `\   revolver. And since he's so busy, you'd probably have to run up |
_o__)              to him real quick and hand it to him.” —Jack Handey |
Ben Finney



More information about the Tutor mailing list