Poonuts Poonuts - 18 days ago 5
Python Question

python compare string in list with item starting with \r\n

Ok so let's say i have a list.

l = ['a', '\r\nb']


And a known item to search for.

search = 'b'


If i type

search in l


It returns
False
. But if i type.

for item in l:
search in item


I will receive

False
True


The latter one makes sense to me since
'b'
is in
'\r\nb'
. But why oh why isn't
'b'
in
['a', '\r\nb']

Answer

Because in the first case (search in l) it will try to find exact match for any element of the list with your search term .

And when you try to recursively go through each of the element and match it's finding in that element which it succseed to find.

Comments