Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis+ 1
How to extract the dictionary key?
def mostMembers(x): Ā Ā list=[] Ā Ā print("[what alphabet has the biggest number]") Ā Ā for value in sorted(x.values()): #name? Ā Ā Ā Ā list.append(value) Ā Ā for i in list: Ā Ā Ā Ā if list[0]<list[i]: Ā Ā Ā Ā Ā Ā list[0]=list[i] Ā Ā Ā Ā else: Ā Ā Ā Ā Ā Ā pass Ā Ā return list[i] member={'a':5,'b':0,'c':4,'d':7,'e':2,'f':3,'g':0,'h':2} print(mostMembers(member)) I can see the value but I want to get key.
3 Respostas
+ 3
Here, look at this. It does no sorting. It just iterates over the dict directly. Now, let me know whether or not it solves your issue.
https://code.sololearn.com/cFGJqDQZg773/?ref=app
+ 1
thank you so much :)
I will try it again!
+ 1
mydict = {
1: āoneā,
2: ātwoā
}
keys = mydict.keys()
values = mydict.values()
# get the keys or values
for (k, v) in mydict.items():
print(k, v)
# loops key:value pairs