def material_type(rec):
    """Determine material type for record (arg1). 
    
    Returns: 
    A string, one of BK (books), CF (computer files), MP
    (maps), MU (music), CR (continuing resource), VM (visual
    materials), MX (mixed materials)

    """

    l = rec[0]
    
    # Book: Leader/06 (Type of record) contains code a (Language
    # material) or t (Manuscript language material) and Leader/07
    # (Bibliographic level) contains code a (Monographic component
    # part), c (Collection), d (Subunit), or m (Monograph)
    if l[1] in ("a", "t") and l[2] in ("a", "c", "d", "m"):
        return "BK"

    # Computer File: Leader/06 (Type of record) contains code m
    if l[1] == "m":
        return "CF"

    # Map: Leader/06 (Type of record) contains code e (Cartographic
    # material) or f (Manuscript cartographic material)
    if l[1] in ("e", "f"):
        return "MP"

    # Music: Leader/06 (Type of record) contains code c (Notated
    # music), d (Manuscript notated music), i (Nonmusical sound
    # recording), or j (Musical sound recording)
    if l[1] in ("c", "d", "i", "j"):
        return "MU"

    # Continuing resources: Leader/06 (Type of record) contains code a
    # (Language material) and Leader/07 contains code b (Serial
    # component part), i (Integrating resource), or code s (Serial)
    if l[1] == "a" and l[2] in ("b", "i", "s"):
        return "CR"

    # Visual materials: Leader/06 (Type of record) contains code g
    # (Projected medium), code k (Two-dimensional nonprojectable
    # graphic, code o (Kit), or code r (Three-dimensional artifact or
    # naturally occurring object)
    if l[1] in ("g", "k", "o", "r"):
        return "VM"

    # Mixed materials: Leader/06 (Type of record) contains code p
    # (Mixed material)
    if l[1] == "p":
        return "MX"

    raise ValueError