+ 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