0
Python slice text
I have a word and I want check it section by section. If I divide the word as follows: word='systematically' 1. Split the word based on vowels. So we could have : new_list = [] word_list = ['sys','te','ma','ti','cal','ly',] 2. Then check each one and if true based on my conditions, reset the list. If len(word_list[0]) == 3 and word_list[0]== 'CVC': new_list.append(word_list[0]) #here the word list should be reset to a new one till len(word_list) is finished word_list = ['te','ma','ti','cal','ly',] elif len(word_list[0]) == 4: DO THIS elif len(word_list[0]) == 3: DO ABOVE (IF CONDITION). (The first one) What is your idea to implement such an idea?
11 Respostas
+ 3
I would try to filter the wordlist by criteria.
here with len = 3
new_List = list(filter(lambda x: len(x) == 3,word_list))
+ 2
have you asked for something like this before?
I have done the "split on vowels" part but didn't post it because a comment I posted regarding the task didn't get a reply. should still have it in my IDE to home, I'll post tonigh.
+ 2
import re
# example 1.
words = ["work", "because", "function", "systematically"]
for word in words:
print(re.findall(r"[^aeiou]+[aeiou]*", word))
# example 2.
print(re.findall(r"[^aeiou]+[aeiou]*", "systematically"))
# or:-
for x in re.findall(r"[^aeiou]+[aeiou]*", "systematically"):
# do what you need here for each of the substrings.
+ 1
Thanks Jan Markus .
You are right. I searched and find that module but it didn’t updated from so long ago. Is there anything better. (other than nltk)
+ 1
Before I post the code....is there an error in you example:-
"word_list =['sys','te','ma','ti','cal','ly',]"?
.....the "sys" and "te" are not split on vowels?
0
I wanted to split the long words based on vowels (including them) and then based on their length do some if conditions. not only filter those are three characters.
word='systematically'
word_list =['sys','te','ma','ti','cal','ly',]
if the first condition on word_list[0] is true, then
word_list = ['te','ma','ti','cal','ly',]
0
I had some similar questions but about reset the value of list, no!
0
Thanks Jan Markus
I will test it.
0
you are right. it should be based on vowels.
0
I will check and let you know. Thanks for your time.