def sift(seq, keyfunc):
 m = defaultdict(list)
 for i in seq:
  m[keyfunc(i)].append(i)
 return m

def sift ( seq , keyfunc ) : m = defaultdict ( list ) for i in seq : m [ keyfunc ( i ) ] . append ( i ) return m
sift the sequence .