简体   繁体   中英

Generate unique pairs from list several times without duplicates

After reading many threads here I finally have my first own question. I want to write a script in python that takes a file with names and team codes as input and stores them in a list. Then the program is supposed to find random pairs of those people, but team mates shouldn't be in a pair. Whenever a pair is found with random.choice the two people should be pop of the list. So far so easy. But now i want to repeat this process every month and there shouldn't be repeated pairs…

My idea was to store all past combinations in another file and every time a new match is found it first will check in the list if there already has been this pair in the past.

Are there any better ways to do that ?

Would love to get your ideas on that!

If you want to randomize it, you are going to need a way to store previous pairs. Either a file, or a database. It sounds like it is going to be a pretty simple program, so a json file might make the most sense for storage.

Unless I'm missing something (which I often do), I believe checking it against your storage will be the only way to determine if a random pair has been selected before.

Best of luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM