Characters contain themselves?
Sion Arrowsmith
siona at chiark.greenend.org.uk
Tue Apr 11 06:14:13 EDT 2006
Graham Fawcett <graham.fawcett at gmail.com> wrote:
>You could always use an "is-proper-subset-of" function, which is closer
>to the intent of your algorithm. Using Jamitzky's very clever infix
>recipe [1], you can even write it as an infix operator:
>
>#Jamitzky's infix-operator class, abbreviated
>class Infix:
> [ ... ]
>
># define our is-proper-subset operator...
>ips = Infix(lambda a, b: (a is not b) and (a in b))
>
>>>> print 'a' |ips| 'a'
>False
>>>> print 'a' |ips| 'abc'
>True
Unfortunately:
>>> print 'abc' |ips| 'abc'
False
>>> print 'a'+'bc' |ips| 'abc'
True
Which might not be what you want. On the other hand, it's a simple
fix:
>>> ips = Infix(lambda a, b: (a != b) and (a in b))
>>> print 'a' |ips| 'abc'
True
>>> print 'a'+'bc' |ips| 'abc'
False
>[1] http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122
--
\S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
More information about the Python-list
mailing list