Ich bin relativ neu bei Python. Angenommen, ich habe die folgende Zeichenfolge -Löschen unbestimmter Teilzeichenfolgen
tweet1= 'Check this out!! #ThrowbackTuesday I finally found this!!'
tweet2= 'Man the summer is hot... #RisingSun #SummerIsHere Can't take it..'
Jetzt versuche ich, alle Hashtags zu löschen (#) innerhalb der Tweets, so dass -
tweet1= 'Check this out!! I finally found this!!'
tweet2= 'Man the summer is hot... Can't take it..'
Mein Code war -
tweet1= 'Check this out!! #ThrowbackTuesday I finally found this!!'
i,j=0,0
s=tweet1
while i < len(tweet1):
if tweet1[i]=='#':
j=i
while tweet1[j] != ' ':
++j
while i<len(tweet1) and j<len(tweet1):
++j
s[i]=tweet1[j]
++i
++i
print(s)
Dieser Code gibt mir keine Ausgabe und keine Fehler, die mich glauben machen, dass ich die falsche Logik verwende. Gibt es eine einfachere Lösung mit Regex?
'++ i' macht nichts. Die Tatsache, dass es gültige Syntax ist, ist ein Zufall. Du musst sagen "i + = 1". –
Werfen Sie einen Blick auf [Warum gibt es keine ++ und - Operatoren in Python?] (Http://stackoverflow.com/q/3654830) –