Hi,everyone.
My name is Sai krishna, and I'm new to Python as well as Programming.

I wanted to print out all the combinations of a given word.
I am doing it this way:

n='cat'
def arrange(n):
if len(n)==1: #length of word is 1
    print n
elif len(n)==2: # length of word is 2
    print n[0]+n[1]
    print n[1]+n[0]
elif len(n)==3:
    print n[0]+n[1]+n[2]
    print n[0]+n[2]+n[1]
    print n[1]+n[0]+n[2]
    print n[1]+n[2]+n[0]
    print n[2]+n[0]+n[1]
    print n[2]+n[1]+n[0]

This process is quite lengthy, and I have managed to do this for word
containing 5 letters,i,e.,120 combinations
Is there a better way?
Please help.

-- 
cheers!!!
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to