return文がすべてのテストケース(空文字列のもの)を渡すとは思わない。 @FLOTUSは、言及がスペースで進められるべきであるか、むしろツイートの始まりでなければならないので、言及ではありません。だから代わりに空の文字列として渡す必要があります。これを修正する方法については、どんな助けもありがとう!リストから要素を抽出しますか?
def extract_mentions(tweet):
''' (str) -> list of str
Return a list containing all of the mentions in the tweet, in the order, they appear in the tweet.
Note: This definition of a mention doesn't allow for mentions embedded in other symbols.
Note: This definition of a mention doesn't allow for mentions embedded in other symbols.
>>> extract_mentions('@AndreaTantaros - You are a true journalistic professional. I so agree with what you say. Keep up the great work! #MakeAmericaGreatAgain')
['AndreaTantaros']
>>> extract_mentions('I'm joining @PhillyD tonight at 7:30 pm PDT/10:30 pm EDT to provide commentary on tonight's #debate. Watch it here.')
['PhillyD']
>>> extract_mentions('Join me live in @Springfield, @ohio!')
['Springfield, ohio']
>>> extract_mentions('They endured beatings and jail time. They sacrificed their lives for this [email protected]')
[''] '''
return [tag.strip('@') for tag in tweet.split() if tag.startswith('@')]
're.findall(r '\ B @ \ w +'、tweet)'を使用できませんか? https://regex101.com/r/jloffB/1 –
最後の例で空の文字列を含むリストを返すのはなぜですか?空リストを返すべきではありません---すべての(ゼロ)言及のリスト? –