# permutation

Page 1 of 1

## 1 Replies - 1156 Views - Last Post: 23 November 2008 - 10:02 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=73200&amp;s=c8250e362f631d15d353053efc3c140f&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 immila

Reputation: 0
• Posts: 2
• Joined: 23-November 08

# permutation

Posted 23 November 2008 - 02:04 PM

Hello, i am trying to learn Python and here is my problem:
In my program, i am trying to get the following result:
let say i have list of charachters E ['a','c',] and i have a N=3
As a result I should get (9 strings in total) -
aaa
aac
aca
caa
acc
cac
cca
ccc

My function bellow works, but it does not repeat the same char
it will print
ac
ca
need help, thanks

def comb(L1, n, L2=[]):
if not n: return pr(L2)
for i in range(len(L1)):
L2.append(L1.pop(i))
comb(L1, n-1, L2)
L1.insert(i, L2.pop())

Is This A Good Question/Topic? 0

## Replies To: permutation

### #2 KYA

• Wubba lubba dub dub!

Reputation: 3186
• Posts: 19,211
• Joined: 14-September 07

## Re: permutation

Posted 23 November 2008 - 10:02 PM

Here's a string permutation in python that could reversed to solve your problem.