def assign_items(items, tracks):
 costs = []
 for item in items:
  row = []
  for (i, track) in enumerate(tracks):
   row.append(track_distance(item, track))
  costs.append(row)
 matching = Munkres().compute(costs)
 mapping = dict(((items[i], tracks[j]) for (i, j) in matching))
 extra_items = list((set(items) - set(mapping.keys())))
 extra_items.sort(key=(lambda i: (i.disc, i.track, i.title)))
 extra_tracks = list((set(tracks) - set(mapping.values())))
 extra_tracks.sort(key=(lambda t: (t.index, t.title)))
 return (mapping, extra_items, extra_tracks)

def assign_items ( items , tracks ) : costs = [ ] for item in items : row = [ ] for ( i , track ) in enumerate ( tracks ) : row . append ( track_distance ( item , track ) ) costs . append ( row ) matching = Munkres ( ) . compute ( costs ) mapping = dict ( ( ( items [ i ] , tracks [ j ] ) for ( i , j ) in matching ) ) extra_items = list ( ( set ( items ) - set ( mapping . keys ( ) ) ) ) extra_items . sort ( key = ( lambda i : ( i . disc , i . track , i . title ) ) ) extra_tracks = list ( ( set ( tracks ) - set ( mapping . values ( ) ) ) ) extra_tracks . sort ( key = ( lambda t : ( t . index , t . title ) ) ) return ( mapping , extra_items , extra_tracks )
given a list of items and a list of trackinfo objects .