text = """ sam 
may 
sam 
gray 
bet 
four 
vet 
large """
find = "a"
words = text.split("\n")
for w in words:
  if find in w:
    print(w)
  else :
    pass
What could I add to make this code not print 'sam' (in this case) twice?
text = """ sam 
may 
sam 
gray 
bet 
four 
vet 
large """
find = "a"
words = text.split("\n")
for w in words:
  if find in w:
    print(w)
  else :
    pass
What could I add to make this code not print 'sam' (in this case) twice?
Try this:
text = """
sam 
may 
sam 
gray 
bet 
four 
vet 
large """
find = "a"
used = []
words = text.split("\n")
for w in words:
  if find in w and w not in used:
    print(w)
    used.append(w)
  else :
    pass
