import struct


def unpack(fmt, s):
    """
    Partially unpack `s` according to `fmt`. Returns a
    tuple containing the unpacked elements, and the portion of `s` leftover
    after unpacking.
    """
    s_len = struct.calcsize(fmt)
    first, rest = s[:s_len], s[s_len:]
    return struct.unpack(fmt, first), rest