14,920,009 members
1.00/5 (1 vote)
See more:
Hey guys what,s up This is you,r boy ubaid and today I am back with another problem which i am trying to understand from past 3days.So guys I need you,r assistance in understading this

def permute(s):

out = []

if len(s) == 1:
return s

else:

for i,let in enumerate(s):

for perm in permute(s[:i] + s[i+1:]):

out += [let + perm]

return out

This is the code of permuutation and this uses recursion and I have rolled on my head from past3 days on this little code and I still don,t understand it. Bassically All i need to understand is what is that let for and how this code makes permutations of the rest of letter if you will explain it how and when it does in detail I thinkk that will solove my issue.

What I have tried:

Rolled my head from past 3days on this problem ..
Posted
Updated 25-Jan-19 0:30am
Richard MacCutchan 25-Jan-19 8:56am

This is a classic example of poorly written code. The names of the variables are all too short and give no idea of either their type or function. This is especially a problem in a language like python which does not use strict typing.

## Solution 1

`let` is the current 'enumerated' item of the list (whereas `i` is the corresponding index).
I think the best way for understanding such a code is by mental (pencil and paper are optional) execution: try to execute mentally the following code:
Python
```l = ["a","b","c"]
permute(l)```
Member 14068174 25-Jan-19 7:06am

I already understand trhatbut i don,t understand how it makes different permutations of a word , for e.g abc how it makes acb and abc .. How these two different permutations are made
CPallini 25-Jan-19 7:43am

Try to write down all that happens to the `out` list during program (mental) execution.
Member 14068174 25-Jan-19 10:35am

Tried that too sir, I would appreciate if you would have a vedio call with me..
CPallini 28-Jan-19 15:14pm

Have a look at my latest tip/trick:
https://www.codeproject.com/Tips/1275693/Recursive-Permutations-in-Python