Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # all_permutations_by_length.py
- def permutations(l, n, str_a=''):
- if len(str_a) == n:
- print str_a
- else:
- for c in l:
- permutations(l, n, str_a+c)
- zzz = permutations("ABC", 3)
- '''
- output...
- AAA
- AAB
- AAC
- ABA
- ABB
- ABC
- ACA
- ACB
- ACC
- BAA
- BAB
- BAC
- BBA
- BBB
- BBC
- BCA
- BCB
- BCC
- CAA
- CAB
- CAC
- CBA
- CBB
- CBC
- CCA
- CCB
- CCC
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement