实例:查询字符串首字母在字符串中的位置
"""
举例:查询出字符串中每个单词的首字母在字符串中的位置
"""
str1 = "Beautiful is better than ugly,Explicit is better than implicit."
def index_word(text):
if text:
yield 0
for index, letter in enumerate(text):
if letter == " ":
yield index + 1