Wie kann ich nach einem Schlüssel eines Unterschlüssels in einem Wörterbuch bitten?

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Wie kann ich nach einem Schlüssel eines Unterschlüssels in einem Wörterbuch bitten?

by Anonymous » 30 Apr 2025, 21:17

Wenn ich ein Wörterbuch in einem Wörterbuch habe, wie kann ich dann in einer konstanten Zeit um einen Schlüssel bitten?
Zum Beispiel: < /p>

Code: Select all

def get_hobby(hobby):
d = {'An' : {'Hobby': "Paintball", 'Age' : 22}, 'Jef' : {'Hobby' : "Football", 'Age': 24}, 'Jos' : {'Hobby': "Paintball", 'Age' : 46}}
assert get_hobby("Paintball") == ['An', 'Jos']
< /code>

Dies funktioniert nicht: < /p>

return d.keys[hobby]

Top