mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-30 04:36:08 -04:00
typo fixed in the comb.py 👽
This commit is contained in:
parent
62601a8556
commit
792a269597
Binary file not shown.
@ -3,21 +3,24 @@
|
|||||||
__author__ = "bt3"
|
__author__ = "bt3"
|
||||||
|
|
||||||
|
|
||||||
def comb_str(l1):
|
def combinations(s):
|
||||||
|
'''
|
||||||
if len(l1) < 2:
|
>>> combinations('abc')
|
||||||
return l1
|
['abc', 'acb', 'bac', 'bca', 'cab', 'cba']
|
||||||
|
>>> combinations('')
|
||||||
result = []
|
''
|
||||||
for i, c in enumerate(l1):
|
'''
|
||||||
result.append(c)
|
if len(s) < 2:
|
||||||
for comb in comb_str(l1[i+1:]):
|
return s
|
||||||
result.append(c + comb)
|
res = []
|
||||||
|
for i, c in enumerate(s):
|
||||||
return result
|
res.append(c)
|
||||||
|
for j in combinations(s[:i] + s[i+1:]):
|
||||||
|
res.append(c + j)
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
l1 = ['a', 'b', 'c']
|
import doctest
|
||||||
print comb_str(l1)
|
doctest.testmod()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user