[英]The long_words function returns all words that are at least 7 characters. Fill in the regular expression to complete this function
Can anyone help me with this code?任何人都可以帮我处理这段代码吗?
import re
def long_words(text):
pattern = ___
result = re.findall(pattern, text)
return result
print(long_words("I like to drink coffee in the morning.")) # ['morning']
print(long_words("I also have a taste for hot chocolate in the afternoon.")) # ['chocolate', 'afternoon']
print(long_words("I never drink tea late at night.")) # []
I need help我需要帮助
import re
def long_words(text):
pattern = "\w{7,}"
result = re.findall(pattern, text)
return result
text='I like to drink coffee in the morning.'
print(long_words("I like to drink coffee in the morning.")) # ['morning']
print(long_words("I also have a taste for hot chocolate in the afternoon.")) # ['chocolate', 'afternoon']
print(long_words("I never drink tea late at night.")) # []
Here, \w
matches the word and {7,}
searches for minimum length of 7这里,
\w
匹配单词并且{7,}
搜索最小长度为 7
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.