Lab 11: Streams, Sets, and Binary Trees

Streams

Big Ideas

Examples

Other Notes

Sets

Big Ideas

Example

>>> s = {1, 1, 2, 2, 3, 3}
>>> t = {3, 4, 4}
>>> len(s) # duplicates are removed
3
>>> len(t)
2
>>> t.remove(4)
>>> 4 in t # Python doesn't care that we originally added two 4s
False
>>> t.add(4) # at this point, t is {3, 4} again
>>> s - t # equivalent to s.difference(t); everything in s that's not in t
{1, 2}
>>> t - s
{4}
>>> s | t # equivalent to s.union(t); everything in either s or t
{1, 2, 3, 4}
>>> s & t # equivalent to s.intersection(t); everything in BOTH s and t
{3}
>>> s & t | s - t | t - s
{1, 2, 3, 4}
>>> s & t | t - s
{3, 4}

Other Notes

Binary Trees

Big Ideas