FAQ

On 2002-06-13, Bjorn Pettersen wrote:

Ok, how about:
class mystr(str):
... def __contains__(self, s):
... return self.find(s) >= 0
...
'hello' in mystr('hello world')
1
'foo' in mystr('hello world')
But that's not readable to someone not familiar with your mystr()
definition. Maybe call the class `substrings':
'hello' in substrings('hello world')
1

Or maybe `xsubstrings' to calm down the reader who would suspect that you
actually generated all substrings...

--
Beni Cherniavsky <cben at tx.technion.ac.il>

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

People

Translate

site design / logo © 2022 Grokbase