We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
if at least one element of s1 exist in s2 than any(i in s2 for i in s1 ) will be True and Yes will be returned, if no element of s1 exist in s2 then any(i in s2 for i in s1 ) will be False which will return 'No'.
any(iins2foriins1)
e.g.:
s1='rtyub's2='abcd'
any(i in s2 for i in s1 ) will evaluate each s1 element as follows:
'r' in 'abcd' ===> False
't' in 'abcd' ===> False
'y' in 'abcd' ===> False
'u' in 'abcd' ===> False
'b' in 'abcd' ===> True
since at least one True is found then return Yes.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Two Strings
You are viewing a single comment's thread. Return to all comments →
if at least one element of s1 exist in s2 than
any(i in s2 for i in s1 )
will be True and Yes will be returned, if no element of s1 exist in s2 thenany(i in s2 for i in s1 )
will be False which will return 'No'.e.g.:
any(i in s2 for i in s1 )
will evaluate each s1 element as follows:since at least one True is found then return Yes.