I am trying to test if some words are in a sentence, as per the code below. Unfortunately the first in I would like to mean:
- test if the sentence contains x,
- But I think its taking it as sentence is looping over something.
How does one correct the below code:
Very confused, in a new terminal it works:
Python 3.8.10 (default, Jun 2 2021, 10:49:15)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> words = ['foo', 'bar']
>>> sentence = 'Some sentence bar the beach'
>>> match = any(x in sentence for x in words)
>>> match
True
But in a pdb it doesnt:
(Pdb) words = ['foo', 'bar']
(Pdb) words
['foo', 'bar']
(Pdb) sentence = 'Some sentence bar the beach'
(Pdb) sentence
'Some sentence bar the beach'
(Pdb) match = any(x in sentence for x in words)
*** NameError: name 'sentence' is not defined
(Pdb)
Okay I see the code is working, but not in the pdb, what is the gotcha with the pdb?