mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-23 08:51:31 -04:00
Change the dir structure slightly
This commit is contained in:
parent
6b6fe21db3
commit
2f4a9638c0
184 changed files with 0 additions and 21 deletions
|
@ -1,37 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
__author__ = "bt3"
|
||||
|
||||
|
||||
''' Write code to generate all possible case permutations of a given
|
||||
lower-cased string
|
||||
'''
|
||||
|
||||
def alpha_permutation(string):
|
||||
'''
|
||||
>>> alpha_permutation('0ab')
|
||||
['0Ab', '0Ab', '0ab', '0ab', '0Ba', '0Ba', '0ba', '0ba', 'ab0', 'a0b', 'a0b', 'b0a', 'b0a', 'ba0']
|
||||
>>> alpha_permutation('')
|
||||
''
|
||||
'''
|
||||
|
||||
if len(string) < 2:
|
||||
return string
|
||||
|
||||
result = []
|
||||
|
||||
for i, c in enumerate(string):
|
||||
rest = string[i+1:] + string[:i]
|
||||
for cc in alpha_permutation(rest):
|
||||
if cc.isalpha():
|
||||
result.append(c.upper() + cc)
|
||||
result.append(c + cc)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import doctest
|
||||
doctest.testmod()
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue