我的问题是输入字符串并获得句子的第三个单词。该部分已解决。第二部分是获取每个单词的第一个字母,但由于某种原因,我获得了句子最后一个单词的两倍
def words():
global sent
sent=input('enter a sentence - ')
word=sent.split()
return sent.split()[2]
print (words())
def first_letter():
word=sent.split()
c=0
for j in sent:
if j==' ':
c+=1
num_words=c+1
for k in range(0,num_words):
frst_letter=word[k]
return word[k]
print(first_letter())
我希望程序能给我句子中每个单词的第一个字母
答案 0 :(得分:0)
尝试:
# Change all values to a Friday
dfdate[wday(dfdate) == 7] <- dfdate[wday(dfdate) == 7] - 1 # Saturdays to Fri
dfdate[wday(dfdate) == 1] <- dfdate[wday(dfdate) == 1] - 2 # Sundays to Fri
dfdate
[1] "2019-04-26" "2019-04-26" "2019-04-26"
输出
sent = "hello there, how do you do?"
def first_letter():
word=sent.split()
return [c[0] for c in word]
print(first_letter())