""" CS 101 Data Structures examples """ def histogram1(s): """ Return dictionary of frequences of characters in string s """ d = dict() for c in s: if c in d: d[c] += 1 else: d[c] = 1 return d def histogram2(s): """ Return dictionary of frequences of characters in string s """ d = dict() for c in s: d[c] = d.get(c,0)+1 return d def vowels(s): """ Test whether all vowels a,e,i,o,u appear in string s """ return set('aeiou') <= set(s) def overlap(s, t): """ Return set of letters that appear in both strings s and t """ return set(s) & set(t) class Point: """ Point class has x and y coordinates """ def __init__(self, x=0, y=0): self.x = x self.y = y import turtle as t def drawPoints(points): """ Demo of drawing points with the turtle """ for p in points: t.goto(p.x, p.y) t.dot()