Deduplication of Python List!

Asked 1 weeks ago, Updated 1 weeks ago, 1 views

Task: Modify the code so that 8 groups of the group draw program are drawn at once without duplication!

import random
import tkinter

# Group draw function
def lotto():
    teams = [
        {'Group 1': [Kim Il-il', '2-3-4, '3-4-5, '987']}
        {'Group 2: Lee Mingi', 'Han Yeseul', 'Jang Dong-gun', 'Lee Byung-heon']
        {'Article 3:' Lee Mi-sun', 'Gumiho', 'Shin-chan', 'Kim Cheol-soo',
        {'Article 4:'Shin Hyung-man', 'No Jin-gu', 'Tung-tung', 'Kim Gae-dung',
        {'Article 5: Hong Gil-dong', 'Kim Gana', 'Lee Shrimp', 'Yoo Mi-rae', 'Nam Beauty']}
        {'Group 6:'Corona', 'Cho Draw', 'Park Namu', 'Kim Seobang', 'Gang Daebak']

    team = random.choice(teams) #Team draw. Return is dictionary
    leader = list(team.keys())

    textts = leader[0] + '\n' + str(team[leader[0]]) + '\n' + "Team: {0}".format(
        team[leader[0][0]) + '\n' + f' presenter: {random.choice(team[leader[0])}}'
    lbl_people.config(text = texts)

# Invoke the lotto function when an event occurs when the enter key is pressed
def lotto_enter(ev):

# Main function.Front end
if __name__ == '__main__':
    win = tkinter.Tk() # Create Window
    win.title ("Health and Medical Information Project")

    # Label, button generation, button associated with lotto function
    lbl_people = tkinter.Label (text="presentation draw")
    btn_lotto=tkinter.Button (text="group draw", bg="yellow", fg="green", command=lotto)

    # Enter key processing
    win.bind('<Return>', lotto_enter)

    # Attach labels and buttons to windows

    li = ["Group 1", "Group 2", "Group 3", "Group 4", "Group 5", "Group 6"]
    choiceList = random.choice(li)


It's a group drawing program, and I have to make sure that 6 groups are randomly extracted without duplication, but I don't know where to modify it. No matter how many times I put in the code, I keep getting errors, so how should I solve it?

python list

2022-09-20 15:00

1 Answers

Extracting without duplication is simple.

When extracting, remove the element from an existing list, or When extracting, make sure that the element is already extracted, and then extract it.

In other cases, I'll help you a little more, but... I think this is enough because you have to do the assignment yourself.

In the case of deduplication of the list, there were many similar questions, so you can find a lot of data even if you search a little bit.

2022-09-20 15:00

If you have any answers or tips

© 2022 pinfo. All rights reserved.