<div dir="ltr"><br clear="all">Hi,everyone.<br>My name is Sai krishna, and I'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='cat'<br>def arrange(n):<br>if len(n)==1: #length of word is 1<br> print n<br>elif len(n)==2: # length of word is 2<br> print n[0]+n[1]<br> print n[1]+n[0]<br>elif len(n)==3:<br> print n[0]+n[1]+n[2]<br>
print n[0]+n[2]+n[1]<br> print n[1]+n[0]+n[2]<br> print n[1]+n[2]+n[0]<br> print n[2]+n[0]+n[1]<br> 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>