So I am trying to pull information from a dictionary list that I made in a specific format but for the life of me I cannot create a loop that pulls the information from exactly where I need it at all, it prints nothing but I receive no errors. Here's an example:
class Global():
prv_word = 'dumb'
cur_word = 'dog'
nxt_word = 'head'
class Animal():
dog = [
{'head': {'funny': [8 , 7 , 1],'dumb': [9 , 3 , 2],'poofy': [18 , 4 , 11]}},
{'tail': {'funny': [12, 2 , 4], 'dumb': [3 , 9 , 7],'poofy':[28 , 5 , 60]}}]
dog_cur = f'Animal.{Global.cur_word}'
if hasattr(Animal, Global.cur_word):
for list in dog_cur:
if Global.nxt_word in list:
adj = Global.nxt_word
index = list.index(Global.nxt_word)
for lis in list:
if Global.prv_word in lis:
adj2 = Global.prv_word
index2 = lis.index(Global.prv)
end = dog_cur[index][adj][adj2]
print(end)
##### TROUBLESHOOT #####
##### This works! But how do I format the loop to generate this result? #####
(print(Animal.dog[0]['head']['dumb']))
can someone help show me a way to make this loop pop up with a relevant value of [9, 3, 2]
.
I also don't think the formatted dog_cur
variable will work... Is there another way to format that variable to equal the same result as f'Animal.{Global.cur_word}'
I believe if you look at my loop, you'll be able to see I'm trying to pull the values from a list within a dictionary. In my actual program, the Global values are constantly changing so that's why I need a loop that can find those values. Help will be greatly appreciated! Thank you