Monday, November 24, 2014

python_set_functions

Table from: https://docs.python.org/2/library/sets.html

OperationEquivalentResult
len(s)cardinality of set s
x in stest x for membership in s
x not in stest x for non-membership in s
s.issubset(t)s <= ttest whether every element in s is in t
s.issuperset(t)s >= ttest whether every element in t is in s
s.union(t)s | tnew set with elements from both s and t
s.intersection(t)s & tnew set with elements common to s and t
s.difference(t)s - tnew set with elements in s but not in t
s.symmetric_difference(t)s ^ tnew set with elements in either s or t but not both
s.copy()new set with a shallow copy of s

No comments:

Post a Comment

JSON file I/O and GDC metadata download

What is JSON? JSON is short for javascript object notation. It is a short format for the XML, record sample information in a shorter/simpl...