This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
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. Optionally, it receives a callable as the test function.

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
>>> one((10, 20, 30, 42), lambda i: i > 40)
42

Install

pip install one

Usage

from one import one

Patterns and use cases

one could replace the following patterns:

true_values = [i for i in iterable if cmp(i)]
if len(true_values) == 1:
    return true_values[0]
return False

# using one
return one(iterable, cmp)

Another pattern, is in a complex condition

if ((a and not b and not c) or
     (b and not a and not c) or
      (c and not a and not b)):
    do_something()

# using one
if one((a, b, c)):
    do_something()

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')

Send me your examples!

Release History

Release History

0.2.1

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
one-0.2.1-py2.py3-none-any.whl (4.2 kB) Copy SHA256 Checksum SHA256 2.7 Wheel Sep 24, 2014
one-0.2.1.tar.gz (5.0 kB) Copy SHA256 Checksum SHA256 Source Sep 24, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting