Skip to main content
deleted 7 characters in body
Source Link
kindall
  • 185.3k
  • 36
  • 291
  • 321

Define your words as a nested dictionary structure.

words = {
    'movies': [
        'Thor',
        'Tangled',
        'Frozen',
        'Spider-Man: No Way Home'
    ],
    'animals': [
        'Zebra',
        'Porcupine'
    ],
    'characters': [
        'Mickey Mouse',
        'Loki Odinson'
    ]
}

Then write your code to first choose a random category, then a word from that category.

def get_word():
    type_of_word = random.choice(list(words.keys()))
    word = random.choice(words[type_of_word])
    return word

print(get_word())

Define your words as a nested dictionary structure.

words = {
    'movies': [
        'Thor',
        'Tangled',
        'Frozen',
        'Spider-Man: No Way Home'
    ],
    'animals': [
        'Zebra',
        'Porcupine'
    ],
    'characters': [
        'Mickey Mouse',
        'Loki Odinson'
    ]
}

Then write your code to first choose a random category, then a word from that category.

def get_word():
    type_of_word = random.choice(list(words.keys()))
    word = random.choice(words[type_of_word])
    return word

print(get_word())

Define your words as a nested dictionary structure.

words = {
    'movies': [
        'Thor',
        'Tangled',
        'Frozen',
        'Spider-Man: No Way Home'
    ],
    'animals': [
        'Zebra',
        'Porcupine'
    ],
    'characters': [
        'Mickey Mouse',
        'Loki Odinson'
    ]
}

Then write your code to first choose a random category, then a word from that category.

def get_word():
    type_of_word = random.choice(list(words))
    word = random.choice(words[type_of_word])
    return word

print(get_word())
Source Link
kindall
  • 185.3k
  • 36
  • 291
  • 321

Define your words as a nested dictionary structure.

words = {
    'movies': [
        'Thor',
        'Tangled',
        'Frozen',
        'Spider-Man: No Way Home'
    ],
    'animals': [
        'Zebra',
        'Porcupine'
    ],
    'characters': [
        'Mickey Mouse',
        'Loki Odinson'
    ]
}

Then write your code to first choose a random category, then a word from that category.

def get_word():
    type_of_word = random.choice(list(words.keys()))
    word = random.choice(words[type_of_word])
    return word

print(get_word())