need help printing the variable behind an option in a list

hello, i need help printing the variable behind an option chosen by the user from a pre-given list
when you start the program it asks you to choose an option from a list of personalities to hear a quote from them, it then should print the answer then printing the variable, the quote, behind the chosen option

heres the code: https://replit.com/@alex66613/hi-level-2-testing?v=1

def choose_from_list(list):    
  print("\thi, my name is alex, i like coding i guess *eye roll*\n \t\twould you like to choose a personality from our\n listings to hear fake and real quote of theirs based on\n their catchphrases/personalites, etc?\n")
  print("\n".join(list))    
  ans = input()             
  if ans in list:
    print(ans)
  while ans not in list:    
    print("\t\t\t\t-option unavailable.")
    ans = input("choose an option listed above: ")
  return ans    # return what the user chose


my_list = ["NarutoUzumaki",
"Kurama", "BorutoUzumaki", "HimawariUzumaki", "Kawaki-Uzumaki (Otsutski/*unknown*)", "Hinata-Uzumaki (Hygua)", "NagatoUzimaki", "SasukeUchiha", "ItachiUchiha", "MadaraUchiha", "ObitoUchiha", "ShisuiUchiha", "Sakura-Uchiha (Haruno)", "KaguyaOtsutsuki", "IsshikiOtsutsuki", "HagoromoOtsutsuki", "IndraOtsutsuki", "AsuraOtsutsuki", "KakashiHatake", "MaitoGai", "RockLee", "NejiHyuga", "HinataHyuga", "SakuraHaruno", "ShikamaruruNara", "ShikakuNara", "Gaara", "Temari", "Kankuro", "Kabuto Yakushi", "Orochimaru", "JiraiyaOgataShumaHiroyuki", "TsunadeSenju", "HashiramaSenju", "TobiramaSenju", "HiruzenSarutobi", "KonohamaruSarutobi", "AsumaSarutobi", "Danzo Shimura"]
user_choice = choose_from_list(my_list)

NarutoUzumaki = "I'm Naruto Uzumaki! I'm gonna be hokage one day!"
Kurama = "Naruto, let's show them our power."
BorutoUzumaki = "Today's an important day for a dad, you know why, right?"
Batman = "I am, vengeance." "suggested followup search: Bruce Wayne*"
BruceWayne = "Let's go, Alfred, it's tea time." "*suggested followup search: Alfred*"
Alfred = "Indeed, I'll get your coat master, Bruce."
}

thank you if anyone can help!~

Hey there @alex66613, I’d suggest you look into a data structure called a dictionary. It’s what’s called a key-value-pair data structure. The simplest way I can describe them is like a list, but where instead of the indices being 0 → n, you can kind of “name” them with different values.

For example:

my_dictionary = {
    1: 2,
    "one": "two",
    "three": 4,
    "cactus": "spiky",
    True: [1, 2, 3]
}

# You access each value the same as a list with the square brackets syntax:
my_dictionary[1] # => 2
my_dictionary["one"] # => "two"
my_dictionary["three"] # => 4
my_dictionary["cactus"] # => "spiky"
my_dictionary[True] # => [1, 2, 3]

In your case, I’d suggest a structure like this (based on your variables):

quotes = {
    "NarutoUzumaki": "I'm Naruto Uzumaki! I'm gonna be hokage one day!",
    "Kurama": "Naruto, let's show them our power.",
    "BorutoUzumaki": "Today's an important day for a dad, you know why, right?",
    "Batman": "I am, vengeance." "suggested followup search: Bruce Wayne*",
    "BruceWayne": "Let's go, Alfred, it's tea time." "*suggested followup search: Alfred*",
    "Alfred": "Indeed, I'll get your coat master, Bruce."
}

# e.g.
quotes["Alfred"] # => "Indeed, I'll get your coat master, Bruce."

More reading: Python Dictionary - GeeksforGeeks

2 Likes