+ 1

I made a generator to make a group from a pool of players but I can only make 1 group ,

https://code.sololearn.com/cyC0xHINuJMh/?ref=app How do I make a second and third group without including any of the people from the first group

22nd Apr 2020, 2:48 PM
Muhammad Gaffar
Muhammad Gaffar - avatar
8 ответов
+ 1
a = "".join([random.choice(str1)for x in range(1) ]) # why are you doing it this way? Although it will work......, here's how I would do it.. (but you must change your tuples to lists for this to work.) a = random.choice(str1)....then... str1.remove(a) Now the element chosen by the random.choice has been removed from the str1 ready to start your group2 selections.
22nd Apr 2020, 5:33 PM
rodwynnejones
rodwynnejones - avatar
+ 1
Thank you for writing the code , I will try to understand it and learn from it
22nd Apr 2020, 6:25 PM
Muhammad Gaffar
Muhammad Gaffar - avatar
0
rodwynnejones I searched it on internet ad I've only done a small part of the python course ,so where exactly would I put the str1.remove(a) , after the variable a or at the end after print and thanks for assisting me
22nd Apr 2020, 5:38 PM
Muhammad Gaffar
Muhammad Gaffar - avatar
0
a = random.choice(str1) b = random.choice(str2) c = random.choice(str3) d = random.choice(str4) str1.remove(a) str2.remove(b) str3.remove(c) str4.remove(d) group1 = a + b + c + d print(group1) # Now start the code for group 2. # Although you can put this code in to a "for loop" # and append to a pre-declared list eg "groups" then # unpack into "group1", "group2", "group3" etc... # just to add...are you sure you need str4, as the same name # can be picked twice as str4 is str1 + str2 + str3? # but that's up to you.
22nd Apr 2020, 6:04 PM
rodwynnejones
rodwynnejones - avatar
0
Thank you, I'm using str 4 so it cam be a group of 4 , if it produces the same name twice I just re run it
22nd Apr 2020, 6:06 PM
Muhammad Gaffar
Muhammad Gaffar - avatar
0
And the for loop is abit complicated for me as I'm still new and trying out stuff with what the basics i know
22nd Apr 2020, 6:07 PM
Muhammad Gaffar
Muhammad Gaffar - avatar
0
rodwynnejones I see the method with remove works but is very long , I will try to look into and understand the for method
22nd Apr 2020, 6:13 PM
Muhammad Gaffar
Muhammad Gaffar - avatar
0
Once you put it into a loop it's not that long:- https://code.sololearn.com/cle445E1HhTn/#py
22nd Apr 2020, 6:23 PM
rodwynnejones
rodwynnejones - avatar