<div dir="ltr"><br clear="all">Hi,everyone.<br>My name is Sai krishna, and I&#39;m new to Python as well as Programming.<br><br>I wanted to print out all the combinations of a given word.<br>I am doing it this way:<br><br>
n=&#39;cat&#39;<br>def arrange(n):<br>if len(n)==1: #length of word is 1<br>&nbsp;&nbsp;&nbsp; print n<br>elif len(n)==2: # length of word is 2<br>&nbsp;&nbsp;&nbsp; print n[0]+n[1]<br>&nbsp;&nbsp;&nbsp; print n[1]+n[0]<br>elif len(n)==3:<br>&nbsp;&nbsp;&nbsp; print n[0]+n[1]+n[2]<br>
&nbsp;&nbsp;&nbsp; print n[0]+n[2]+n[1]<br>&nbsp;&nbsp;&nbsp; print n[1]+n[0]+n[2]<br>&nbsp;&nbsp;&nbsp; print n[1]+n[2]+n[0]<br>&nbsp;&nbsp;&nbsp; print n[2]+n[0]+n[1]<br>&nbsp;&nbsp;&nbsp; print n[2]+n[1]+n[0]<br><br>This process is quite lengthy, and I have managed to do this for word containing 5 letters,i,e.,120 combinations<br>
Is there a better way?<br>Please help.<br><br>-- <br>cheers!!!<br>
</div>