定义一个函数isIn(char, sTr), 来判断char(为单个字母)是否在字符串sTr中。
Note:
‘a’ < ‘b’, ‘a’ > ‘Z’
语法: ‘sep’.join(seq)
seq:要连接的元素序列、字符串、元组、字典
返回值:返回一个以分隔符sep连接各个元素后生成的字符串
def isIn(char, aStr):
'''
char: a single character
aStr: an alphabetized string
returns: True if char is in aStr; False otherwise
'''
# Your code here
def tC(aStr):
L = list(aStr)
L.sort()
res = ''.join(L)
return res
if char == tC(aStr)[len(tC(aStr))/2]:
return True
elif char != tC(aStr)[len(tC(aStr))/2] and len(tC(aStr)) == 1:
return False
elif char > tC(aStr)[len(tC(aStr))/2]:
return isIn(char, tC(aStr)[len(tC(aStr))/2:])
elif char < tC(aStr)[len(tC(aStr))/2]:
return isIn(char, tC(aStr)[:len(tC(aStr))/2])