Not all nor any. Just the one.
Project description
Not all nor any: just the one.
one is a simple function to check if there is a unique value that evaluates to True in an iterable, and return it.
Examples:
>>> from one import one
>>> one((True, False, False))
True
>>> one((True, False, True))
False
>>> one((0, 0, 'a'))
'a'
>>> one((0, False, None))
False
>>> one((True, True))
False
>>> one(('', 1))
1
Install
pip install one
Use cases
A very frequent case is when you have values that must exclude each others.
class ShopStore(models.Model):
address = models.CharField(max_length=200, null=True, blank=True)
is_online = models.BooleanField(default=False)
def clean(self):
if not one((self.address, self.is_online)):
raise models.ValidationError(u'A shop must be online or physical, but not both')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
one-0.1.0.tar.gz
(4.5 kB
view details)
Built Distribution
File details
Details for the file one-0.1.0.tar.gz
.
File metadata
- Download URL: one-0.1.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5b2e82372c5c548a640930229cfaf23327421bfaeecc37c54911b6cdd8140e9 |
|
MD5 | 67d97d19436a6d3d692a28c83133ec97 |
|
BLAKE2b-256 | 3ebfdd5eeec131f428dc4619dfa492128cd5f62f132143741107dafbee0647b4 |
File details
Details for the file one-0.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: one-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 396ea17447706573886746c47b479fcb4fb803e0f4f6cce2755e9aa6b55b07bb |
|
MD5 | 56ac98a60b1230b52bdb05747a6ca90b |
|
BLAKE2b-256 | b0b20280ba47b2cdd7fc6a0d7d822ad0edc61c9693ee7e5ed33c7b99272fe3f2 |