|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
I have just seen Sirs Sanjay and Eleonore!
"I am a Knave," whispered Sir Eleonore.
Who is a Knight and who is a Knave?
请问,我想把这三句话放入到一个列表中,然后是0, 1, 2 分别对应这三句话,该如何码呢? 就是 判断以 感叹号,问号,句号结尾的句子,碰到这三个符号就把这三个符号之前的文字连符号保存在为一个列表里面的一个值
本帖最后由 1239890175 于 2019-3-25 15:54 编辑
- str_list=[
- 'I have just seen Sirs Sanjay and Eleonore!',
- '"I am a Knave," whispered Sir Eleonore.',
- 'Who is a Knight and who is a Knave?'
- ]
- new_str_list=[]
- s=''
- for i in range(len(str_list)):
- if (str_list[i][-1]) in ['!','?','.']:
- print (str_list[i])
- s=s+str_list[i]
- new_str_list.append(s)
- print (new_str_list)
复制代码
|
|