def fingers_needed(fingering):
    """Return the number of fingers needed to play the given fingering."""
    split = False # True if an open string must be played, thereby making any
                  # subsequent strings impossible to bar with the index finger
    indexfinger = False # True if the index finger was already accounted for
                        # in the count
    minimum = min(finger for finger in fingering if finger) # the index finger
                                                            # plays the lowest
                                                            # finger position
    result = 0
    for finger in reversed(fingering):
        if finger == 0: # an open string is played
            split = True # subsequent strings are impossible to bar with the
                         # index finger
        else:
            if not split and finger == minimum: # if an open string hasn't been
                                                # played and this is a job for
                                                # the index finger:
                if not indexfinger: # if the index finger hasn't been accounted
                                    # for:
                    result += 1
                    indexfinger = True # index finger has now been accounted for
            else:
                result += 1
    return result
Return the number of fingers needed to play the given fingering.