|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
word = ''' string2'''
lenth = len(word)
list1= []
for each in range(lenth):
i=1
if word[each] == '\n':
continue
for i in range(3):
if word[each-i].isupper and word[each+i].isupper and word[each].islower:
list1.append(each)
print (list1)
这样总是报错,说无法string index out of range,怎么回事呢
本帖最后由 8306最硬 于 2018-1-21 18:49 编辑
可以用切片操作,按你的思路改了下
- word = ''' string2'''
- word = ''.join(word.split())
- lenth = len(word)
- list1= []
- for each in range(lenth):
- if word[each-3:each].isupper()\
- and word[each+1:each+4].isupper()\
- and word[each].islower()\
- and word[each+4].islower()\
- and word[each-4].islower():
- list1.append(word[each])
- print (''.join(list1))
复制代码
|
|