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

保持字典中重復(fù)鍵的最高值

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

問題描述

對(duì)于學(xué)校,我正在編寫一個(gè)小程序來為游戲排名列表.我為此使用字典,將播放器的名稱作為鍵名,將分?jǐn)?shù)作為鍵值.將有 10 場(chǎng)比賽,每場(chǎng)比賽都有一個(gè)自動(dòng)排名系統(tǒng),我將其打印到文件中.我已經(jīng)設(shè)法編寫了排名系統(tǒng),但現(xiàn)在我面臨著一個(gè)更大的挑戰(zhàn),我無法解決:

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:

我必須做一個(gè)整體排名,這意味著某個(gè)玩家名字可以在多個(gè)比賽中獲得多個(gè)分?jǐn)?shù),但我只需要保留副本的最高分?jǐn)?shù).

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.

簡(jiǎn)而言之:我需要一些幫助來保持重復(fù)鍵的最高值:

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}

正常的合并選項(xiàng)只采用第二個(gè)字典,因此采用該值.

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

請(qǐng)?zhí)崆?/p>

推薦答案

你需要有一個(gè)函數(shù)來記錄每個(gè)玩家的最高分?jǐn)?shù).如果還沒有玩家,它會(huì)將玩家添加到總數(shù)中,否則如果它更高,則添加它.像這樣的:

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]

這篇關(guān)于保持字典中重復(fù)鍵的最高值的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區(qū)域周圍繪制一個(gè)矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測(cè)和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個(gè)矩形邊界框中應(yīng)用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據(jù)文本方向檢測(cè)圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測(cè)圖像中矩形的中心和角度)
主站蜘蛛池模板: 精品视频一区在线 | avav在线看 | 九九视频在线观看视频6 | 黄色一级毛片免费看 | 91在线免费视频 | 国产成人精品一区二 | 99国产精品99久久久久久 | 在线播放中文字幕 | 亚洲精品免费在线 | 黄色大片免费播放 | 免费在线看黄视频 | www.婷婷 | 亚洲欧美第一视频 | 亚洲精品91| 日韩色视频 | 天天躁人人躁人人躁狂躁 | av免费看片 | 日批的视频 | 欧美在线观看一区 | 午夜精品久久久久久久久久久久久 | 三级免费毛片 | 激情视频网站 | 国产视频二区 | 亚洲精品乱码久久久久久久久久 | 午夜精品福利视频 | 亚洲国产激情 | 国产成人精品a视频一区www | 欧美女优在线观看 | 日韩在线精品视频 | 欧美亚州综合 | 91精品国产乱码久久久久久久久 | 日韩中文字幕在线免费 | 精品少妇一区二区三区日产乱码 | 亚洲国产精品99久久久久久久久 | 免费在线视频一区二区 | 亚州精品天堂中文字幕 | 久草网址 | 国产精品日韩在线 | 日韩精品免费视频 | 国产亚洲精品久久久久动 | 午夜免费视频观看 |