简体   繁体   English

long_words function 返回至少 7 个字符的所有单词。 填写正则表达式完成这个function

[英]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

learn more about python regex here在此处了解有关 python 正则表达式的更多信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 multi_vowel_words function 返回具有 3 个或更多连续元音(a、e、i、o、u)的所有单词。 填写正则表达式来做到这一点 - The multi_vowel_words function returns all words with 3 or more consecutive vowels (a, e, i, o, u). Fill in the regular expression to do that 8 或 7 个字符的正则表达式 - regular expression for words with 8 or 7 characters 匹配正则表达式的所有单词的列表 - List of all words matching regular expression 为正则表达式查找长度为 0 - 4 的所有单词(方法?) - Finding all words with length 0 - 4 for a regular expression (method?) 编写一个函数 filter_long_words() 接受一个单词列表和一个整数 n 并返回长度大于 n 的单词列表 - Write a function filter_long_words() that takes a list of words and an integer n and returns the list of words that are longer than n 从可以是 A、B 或 C 的 n 个字符中生成所有单词的函数 - Function that generates all words out of n characters that can be A,B or C 带有连接词的正则表达式 - Regular expression with connected words 在正则表达式中过滤单词 - Filter words in Regular expression 给定一个不同单词的列表,实现一个 function 返回包含所有元音的所有单词的列表(不区分大小写) - Given a list of different words, implement a function that returns the list of all words that contain all vowels (case insensitive) 创建一个函数以返回句子中所有大写的单词(不包括逗号) - Creating a function that returns all capitalized words in a sentence (commas excluded)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM