why is ee not in the first place when he is having the most number of coins which is 11 coins? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

why is ee not in the first place when he is having the most number of coins which is 11 coins?

arr = {"a": 2,"b": 3,"k": 10,"c": 4,"j": 9,"d": 5,"ee": 11,"f": 6,"g": 7,"h": 8} abb = ["a","j","ee","b","c","d","k","g","f","h"] for i in abb: for q in arr: if i == q: print(max(abb)) abb.remove(max(abb)) print(max(abb)) abb.remove(max(abb)) print(max(abb)) abb.remove(max(abb)) print(max(abb)) abb.remove(max(abb)) print(max(abb)) abb.remove(max(abb)) """ the government is holding a low-cost housing program because the funds are borne by donors. But because there are so many low-cost house enthusiasts, the government wants to sort out who is the first and who is the last to get a low-cost house. Sorted by who gave the most coins then he became the first order output: k j h g f ee d c b a May Allah bless you if you can solve this problem.

2nd Jan 2022, 4:46 AM
sis nurrohman
sis nurrohman - avatar
5 Answers
+ 3
You may sort the arr first, and max(abb) may be max(arr.values()) ? # sort by dict's value and reverse it arr = sorted(arr.items(), key=lambda x: x[1], reverse=True) That your code looks like: arr = {"a": 2,"b": 3,"k": 10,"c": 4,"j": 9,"d": 5,"ee": 11,"f": 6,"g": 7,"h": 8} abb = ["a","j","ee","b","c","d","k","g","f","h"] arr = sorted(arr.items(), key=lambda x:x[1], reverse=True) for k, v in arr: if k in abb: # print(k, v) print(k)
2nd Jan 2022, 5:05 AM
FanYu
FanYu - avatar
+ 1
I tried my own way jaja abb = {"a": 2,"b": 3,"k": 10,"c": 4,"j": 9,"d": 5,"ee": 11,"f": 6,"g": 7,"h": 8} for _ in range(len(abb)): e = list(abb.keys())[list(abb.values()).index(max(abb.values()))] print(e) abb.pop(e)
2nd Jan 2022, 5:24 AM
CGM
CGM - avatar
0
I'm not a scientist, but it looks like reverse alphabetical order...
2nd Jan 2022, 4:56 AM
CGM
CGM - avatar
0
Good job fan yu, may Allah bless you with a great blessing, aameen
2nd Jan 2022, 5:20 AM
sis nurrohman
sis nurrohman - avatar
0
Ok, Cristian Gabriel Mazzulla, your code also working well so may Allah bless you with a great blessing, aameen
2nd Jan 2022, 5:33 AM
sis nurrohman
sis nurrohman - avatar