blob: 3b21723f44e35824c8f00c3f5afb97fa6b7fb207 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
def IsBuddyStr (strSource, strTarget):
arrSource = list(strSource)
for nRow in range(0, len(arrSource) - 1):
for nCol in range(nRow + 1, len(arrSource)):
arrTemp = arrSource[:]
arrTemp[nRow] = arrSource[nCol]
arrTemp[nCol] = arrSource[nRow]
strSwap = "".join(arrTemp)
if strSwap == strTarget:
return True
return False
## Example 1
## strInputSource = "fuck"
## strInputTarget = "fcuk"
## Example 2
## strInputSource = "love"
## strInputTarget = "love"
## Example 3
## strInputSource = "fodo"
## strInputTarget = "food"
## Example 4
strInputSource = "feed"
strInputTarget = "feed"
print (IsBuddyStr(strInputSource, strInputTarget))
|