久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

保持字典中重復鍵的最高值

keep highest value of duplicate keys in dicts(保持字典中重復鍵的最高值)
本文介紹了保持字典中重復鍵的最高值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

對于學校,我正在編寫一個小程序來為游戲排名列表.我為此使用字典,將播放器的名稱作為鍵名,將分數作為鍵值.將有 10 場比賽,每場比賽都有一個自動排名系統,我將其打印到文件中.我已經設法編寫了排名系統,但現在我面臨著一個更大的挑戰,我無法解決:

For school i am writing a small program for a rankinglist for a game. I am using dicts for this, with the name of the player as keyname, and the score as keyvalue. there will be 10 games, and each game will have an automatic ranking system which i print to file. ive already managed to code the ranking system, but now im facing a bigger challange which i cannot solve:

我必須做一個整體排名,這意味著某個玩家名字可以在多個比賽中獲得多個分數,但我只需要保留副本的最高分數.

I have to make an overall ranking, which means someplayername can be in several contests with several scores, but i need to only keep the highest score of a duplicate.

簡而言之:我需要一些幫助來保持重復鍵的最高值:

In short: I need some help with keeping the duplicate key with the highest value:

像這樣:

dict1 = {"a": 6, "b": 4, "c": 2, "g": 1}
dict2 = {"a": 3, "f": 4, "g": 5, "d": 2}
dictcombined = {'a': 6, 'b': 4, 'c': 2, 'g': 5, 'f': 4, 'd': 2}

正常的合并選項只采用第二個字典,因此采用該值.

the normal merge option just takes the second dict and thus that value.

請提前

推薦答案

你需要有一個函數來記錄每個玩家的最高分數.如果還沒有玩家,它會將玩家添加到總數中,否則如果它更高,則添加它.像這樣的:

You need to have a function that will keep track of the highest scores for each player. It will add a player to the total if not already there, otherwise adding it if it's higher. Something like this:

def addScores(scores, total):
    for player in scores:
        if player not in total or total[player] < scores[player]:
            total[player] = scores[player]

這篇關于保持字典中重復鍵的最高值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 成人激情视频免费在线观看 | 色爱区综合 | 国产日韩精品久久 | 成人在线电影网站 | 国产不卡一区 | 91观看| 蜜桃特黄a∨片免费观看 | 欧美成人在线影院 | 91久久精品一区二区二区 | 91精品国产91久久综合桃花 | 精品入口麻豆88视频 | 亚洲成人精品 | 亚洲视频不卡 | 一级黄色绿像片 | 亚洲一区二区三区在线观看免费 | 日韩高清www| 浮生影院免费观看中文版 | heyzo在线| 亚洲福利网站 | 在线视频 亚洲 | 九九热免费在线观看 | 日韩精品免费视频 | 色欧美片视频在线观看 | 精品国产91久久久久久 | 欧美午夜一区 | 日韩国产在线 | 免费一区二区 | 91传媒在线观看 | 91精品国产综合久久久久久首页 | 日韩在线观看 | 亚洲午夜av久久乱码 | 九九免费视频 | 欧美精品在线播放 | 亚洲高清视频一区二区 | 九色91视频 | 91综合网| 亚州毛片 | 欧美精品福利 | 亚洲精品一区在线 | 成在线人视频免费视频 | 免费激情网站 |