Ich habe eine Liste:Finding Einträge aus Liste in Strings
names = ['Jim','Billy','Diana']
Ich habe eine Datei, in der jede Zeile ist:
Jim and Billy went to see Diana.
Diana was at the Mall.
Billy and Diana are siblings.
Ich brauche die Ausgabedatei aussehen:
'Jim', 'Billy', 'Diana'
'Diana'
'Billy', 'Diana'
Hier ist, was ich habe, die nicht funktioniert:
f = open("storyfile.txt","r")
names = ['Jim','Billy','Diana']
for line in f:
if names in line:
print(names)
f.close()
Das gibt:
TypeError: 'in <string>' requires string as left operand, not list
nicht sicher, was ich anders machen könnte.