Comment

Comment by Kim_Bruning

   if "needle" in haystack:
      print ('haystack.__contains__("needle")')
Is probably the obvious/canonical answer to the question of trying to find a substring.

So obvious that -to be fair- I blanked for a moment too. But 'in' is an operator, not a method (even though it calls __contains__ under the hood) . The question might have been slightly malformed?

parent Kim_Bruning 5 months ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton