winners = [1,3,2,1,2]
numberOfPlayers = 4
items = list("abacabacabacabaccab")

def hasThree(listOfItems):
    itemTypes = list(set(listOfItems))
    for ty in itemTypes:
        if listOfItems.count(ty) >= 3:
            return True
    return False

def playerItems(numberOfPlayers,items,winners):
    table = [[] for i in range(numberOfPlayers)]
    for w in range(len(winners)):
        table[winners[w]].append(items[w])
    return table


def nextWinner(winners,numberOfPlayers,items):
    itemsPerPlayer = playerItems(numberOfPlayers,items,winners)
    nextItem= len(winners)
    possibleWinners=[]
    while len(possibleWinners)==0:
        for playerIndex in range(numberOfPlayers):
            itemsPerPlayer[playerIndex].append(items[nextItem])
            if hasThree(itemsPerPlayer[playerIndex]):
                possibleWinners.append((playerIndex,nextItem))
        nextItem+=1
    return possibleWinners
        
print(nextWinner(winners,numberOfPlayers,items))




