Skip to Content
Secret Recipes of the Python Ninja
book

Secret Recipes of the Python Ninja

by Cody Jackson
May 2018
Intermediate to advanced content levelIntermediate to advanced
380 pages
9h 37m
English
Packt Publishing
Content preview from Secret Recipes of the Python Ninja

bags

  1. Bags can be compared to sets, including other bags. Following, we see how bags are evaluated compared to sets:
      >>> from collections_extended import bag      >>> bag() == set()      True      >>> bag('a') == set('a')      True      >>> bag('ab') == set('a')      False      >>> bag('a') == set('ab')      False      >>> bag('aa') == set('a')      False      >>> bag('aa') == set('ab')      False      >>> bag('ac') == set('ab')      False      >>> bag('ac') <= set('ab')      False      >>> bag('ac') >= set('ab')      False      >>> bag('a') <= bag('a') < bag('aa')      True      >>> bag('aa') <= bag('a')      False
    • First, comparison shows that an empty bag is equal to an empty set.
    • Next, the same, single element in both shows that they are still comparatively equal.
    • Adding a new element to a bag upsets the balance with a single-element set, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The Expanding World of Python

The Expanding World of Python

Dane Hillard

Publisher Resources

ISBN: 9781788294874Supplemental Content