class multimap """ multimap class built upon use of an underlying map for storage ""maptype dict map typecan be redefined by subclass def init (self) """create new empty multimap instance ""create map instance for storage self map self maptype self def iter (self) """iterate through all ( ,vpairs in multimap "" for ,secondary in self map items) for in secondary yield ( , def add(selfkv) """add pair ( ,vto multimap ""create empty listif needed container self map setdefault( ] container append( self + def pop(selfk) """remove and return arbitrary ( ,vwith key (or raise keyerror""may raise keyerror secondary self map[ secondary pop if len(secondary= no pairs left del self map[ self - return (kv def find(selfk) """return arbitrary ( ,vpair with given key (or raise keyerror""may raise keyerror secondary self map[ return (ksecondary[ ] def find all(selfk) """generate iteration of all ( ,vpairs with given key ""empty listby default secondary self map get( ] for in secondary yield ( ,vcode fragment an implementation of multimap using dict for storage the len methodwhich returns self nis omitted from this listing