Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ajout d'une condition pour eviter la repetition des valeurs dans la… #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 37 additions & 14 deletions Liste.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,48 @@

#liste des etudiants
student_List=["Shinny","Nissi","Ibucap","Yaourt","Motema","Peace"]

mi_list=len(student_List)//2

indices=list(range(len(student_List))) #indices de la student_List

maNouvelleList =[]
#creation de la liste " indices" des indices de la liste student_List

indices=list(range(len(student_List)))

for i in range(len(student_List)):
#generation des valeurs
j=random.randint(i,len(student_List)-1)

#permutation des valeurs liées aux indices de la liste "indices"
indices[i],indices[j]=indices[j],indices[i]

""" affectation des valeurs aléatoires aux differentes équipes selon
notre liste consacrée aux indices """

team1=[student_List[i] for i in indices[:mi_list]]
team2=[student_List[i] for i in indices[mi_list:]]
"""
code originale :
for i in range(len(student_List)):
#generation des valeurs
j=random.randint(i,len(student_List)-1) // possibilite de repetition dans la liste


# ce code permet d'eviter les doublant dans la liste :
for i in range (len(indices)): #
#generation des valeurs
while len(maList) <len(indices):
j=random.randint(i,len(student_List)-1)
if j in maList :
continue
else:
maList.append(j)
"""

for i in range (len(indices)):
while len(maNouvelleList) <len(indices):
#generation des valeurs
j=random.randint(i,len(student_List)-1)
if j in maNouvelleList :
continue
else:
maNouvelleList.append(j)

""" team1=[student_List[i] for i in indices[:mi_list]]
team2=[student_List[i] for i in indices[mi_list:]]

"""
team1 =[student_List[i] for i in maNouvelleList[:mi_list]]
team2 =[student_List[i] for i in maNouvelleList[mi_list:]]

print(team1)
print(team2)
print(team2)