Hello,
I am trying to create a list of all the words strating by letter “m” in my string but I don’t manage to have the result as a list (only non define type or multiple lists). I want to use len.list with the result but I can’t with my results.
< wikipedia_text = “The Liplje Monastery is a Serbian Orthodox monastery dedicated to the Annunciation and located in the Municipality of Teslić in northern Republika Srpska. It stands at the widest part of a narrow gorge through which a little river named Bistrica flows. The earliest mention of the monastery is found in a chronicle dated to the second half of the 15th century. The monks of Liplje were active in transcribing religious books during the 17th century.” >
1st one =
Input =
def word_letter(x):
list =
for word in x.split(’ ') :
if word.startswith(“m”) or word.startswith(“M”):
list.append(word)
print(list)
word_m = word_letter(wikipedia_text)
word_m
Output :
[‘Monastery’]
[‘Monastery’, ‘monastery’]
[‘Monastery’, ‘monastery’, ‘Municipality’]
[‘Monastery’, ‘monastery’, ‘Municipality’, ‘mention’]
[‘Monastery’, ‘monastery’, ‘Municipality’, ‘mention’, ‘monastery’]
[‘Monastery’, ‘monastery’, ‘Municipality’, ‘mention’, ‘monastery’, ‘monks’]
2nd one :
Input =
def word_letter(x):
for word in x.split(’ ') :
if word.startswith(“m”) or word.startswith(“M”):
print(word)
word_m = word_letter(wikipedia_text)
word_m
Output =
Monastery
monastery
Municipality
mention
monastery
monks
Could anyone of you help me with that ?
Thank you very much !