[Python-ideas] a in x or in y

Ben Finney ben+python at benfinney.id.au
Thu Feb 13 01:08:49 CET 2014


Ram Rachum <ram.rachum at gmail.com> writes:

> I've often wished for this because the current way is quite verbose:
>
>     'whatever a long string' in x or 'whatever a long string' in y

No need to repeat the literal:

    >>> x = 'foo'
    >>> y = 'bar whatever a long string bar'
    >>> z = 'baz'
    >>> any('whatever a long string' in item for item in [x, y, z])
    True

-- 
 \            “Politics is not the art of the possible. It consists in |
  `\       choosing between the disastrous and the unpalatable.” —John |
_o__)                                    Kenneth Galbraith, 1962-03-02 |
Ben Finney



More information about the Python-ideas mailing list