Created
November 15, 2022 06:09
-
-
Save marcomarkkez/7f859f30877c784b6cc32bd32bca9ef8 to your computer and use it in GitHub Desktop.
Script en Python para dividir tareas en grupos (funciona bien con: tareas = miembros, tareas > miembros, tareas < miembros)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def randGroups(): | |
print("Ingresa los nombres de los miembros o grupos separados por comas") | |
miembros = input() | |
print("Ingresa las tareas separadas por coma") | |
tareas = input() | |
#print("Miembros: ",miembros) | |
#print("Tareas: ",tareas) | |
miems = miembros.split(",") | |
countm = 0 | |
miemsplit = [] | |
for m in miems: | |
miemsplit.append(miems[countm].lstrip()) | |
countm += 1 | |
random.shuffle(miemsplit) | |
tares = tareas.split(",") | |
countt = 0 | |
taresplit = [] | |
for t in tares: | |
taresplit.append(tares[countt].lstrip()) | |
countt += 1 | |
dict = {} | |
if len(miemsplit) < len(taresplit): | |
grupo1 = miemsplit.copy() | |
grupo2 = taresplit.copy() | |
else: | |
grupo1 = taresplit.copy() | |
grupo2 = miemsplit.copy() | |
while len(grupo2) > 0: | |
for gp1 in grupo1: | |
if len(grupo2) == 0: | |
break | |
if len(grupo2) > 1: | |
randy = random.choice(grupo2) | |
else: | |
for g in grupo2: | |
randy = g | |
if gp1 in dict: | |
dict[gp1].append(randy) | |
grupo2.remove(randy) | |
else: | |
dict[gp1] = [randy] | |
grupo2.remove(randy) | |
for g1 in dict: | |
print(g1) | |
for g2 in dict[g1]: | |
print(g2) | |
# Press the green button in the gutter to run the script. | |
if __name__ == '__main__': | |
randGroups() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment