[Patches] [ python-Patches-638095 ] SimpleSets

noreply@sourceforge.net noreply@sourceforge.net
Wed, 13 Nov 2002 17:24:09 -0800


Patches item #638095, was opened at 2002-11-13 20:24
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=638095&group_id=5470

Category: Library (Lib)
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Raymond Hettinger (rhettinger)
Assigned to: Nobody/Anonymous (nobody)
Summary: SimpleSets

Initial Comment:
In the spirit of heapq for lists, this module provides 
set operations for dictionaries.

Virtues:
-- lightweight, fast, and easy to learn
-- works well with any iterable input
-- takes advantage of the existing implementation

Vices:
-- does not support sets of sets
-- need to wrap sets in list() before displaying
-- no operators

This lightweight module (80 lines of code) is meant to 
be a convenient, fast solution for daily tasks which do 
not require the full firepower of the heavyweight Sets 
module.

Examples
--------
print 'IsSet', isset('factoid'), isset('misinformation')
print 'Equals', equals('algorithm','logarithm'), equals
('sin','cos')
print 'Subset', issubset('heart', 'thread'), issubset
('treat','tryst')
a = 'abracadabra'
b = 'alacazam'
print 'Union', list(union(a,b))
print 'Intersection', list(intersection(a,b))
print 'Difference', list(difference(a,b))
print 'SymmetricDifference', list(symmetric_difference
(a,b))
print 'Uniquification', list(set(a))
print 'Cardinality', len(set(a))
print 'Iteration', [letter.upper() for letter in set(a)]
print 'Membership', 'b' in set(a), 'e' in set(a)




----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=638095&group_id=5470