Python 选择多个单词的第一个字母
我需要显示多个单词的第一个字母,这些单词是从列表中的多个项目中收集的 尝试收集列表项,使用Python 选择多个单词的第一个字母,python,python-3.7,Python,Python 3.7,我需要显示多个单词的第一个字母,这些单词是从列表中的多个项目中收集的 尝试收集列表项,使用word.split(“”和song[0][0/1] for word in song: songWords = word.split(" ") songLetter1 = songWords[0][0] songLetter2 = songWords[1][0] print("") print("The artist is", artist, "and the fi
word.split(“”
和song[0][0/1]
for word in song:
songWords = word.split(" ")
songLetter1 = songWords[0][0]
songLetter2 = songWords[1][0]
print("")
print("The artist is", artist, "and the first letter of the song is",
songWord1, songWord2)
希望有“s”和一个数字,这取决于随机选择的项目从.txt文件中读取文本后,可以将其存储在字符串中。我假设字符串看起来像下面的宋文 尝试: 希望这有帮助 如果输入是一个列表
song=["hey","lol"]
for word in song:
songWords = word.split(" ")
songWord1 = songWords[0][0]
print("")
print("The artist is and the first letter of the song is",songWord1)
您的错误/问题是什么?请显示、输入和所需输出您能提供一个示例“song”以及输出“songWord1”和“songWord2”应该是什么样子吗?@Lafexlos它给了我一个超出范围的列表索引error@RamanKishore歌曲只是外部.txt文件中的“歌曲1、歌曲2等”,我的坏歌词应该是songLetter,应该是我想要的信output@15007LRGS不客气。点击答案的“勾号”符号即可接受答案。
song=["hey","lol"]
for word in song:
songWords = word.split(" ")
songWord1 = songWords[0][0]
print("")
print("The artist is and the first letter of the song is",songWord1)