Skip to content

Commit 1540534

Browse files
authored
Merge pull request AllAlgorithms#31 from irxd/master
Add letter case permutation implementation
2 parents 077ab14 + e978c8c commit 1540534

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

strings/letter_case_permutation.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Python implementation of Letter Case Permutation
2+
# Author: Irsyad
3+
4+
# This function will return every possible string with lowercase or uppercase combination of a given string.
5+
# Sample input and output
6+
# letterCasePermutation("abc") will produce ["abc","abC","aBc","aBC","Abc","AbC","ABc","ABC"]
7+
8+
def letterCasePermutation(S):
9+
result = ['']
10+
for char in S:
11+
if char.isalpha():
12+
result = [i+j for i in result for j in [char.lower(), char.upper()]]
13+
else:
14+
result = [i+char for i in result]
15+
print result
16+
return result
17+
18+
# Test
19+
print(letterCasePermutation("a1b2"))

0 commit comments

Comments
 (0)