Ich glaube nicht, dass meine return-Anweisung alle Testfälle (die mit der leeren Zeichenfolge) besteht. Das @FLOTUS ist keine Erwähnung, da eine Erwähnung mit einem Leerzeichen fortfahren sollte oder eher der Anfang eines Tweets sein sollte. Also sollte es stattdessen als leere Zeichenfolge übergeben werden. Jede Hilfe würde geschätzt werden, wie man das repariert!Elemente aus einer Liste extrahieren?
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('@')]
Kannst du 're.findall (r '\ B @ \ w +', tweet)' nicht benutzen? https://regex101.com/r/jloffB/1 –
Warum sollte das letzte Beispiel eine Liste mit einer leeren Zeichenfolge zurückgeben? Sollte es nicht eine leere Liste zurückgeben --- eine Liste aller (Null) Erwähnungen? –