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

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

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

問題描述

對于學校,我正在編寫一個小程序來為游戲排名列表.我為此使用字典,將播放器的名稱作為鍵名,將分數(shù)作為鍵值.將有 10 場比賽,每場比賽都有一個自動排名系統(tǒng),我將其打印到文件中.我已經(jīng)設法編寫了排名系統(tǒng),但現(xiàn)在我面臨著一個更大的挑戰(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:

我必須做一個整體排名,這意味著某個玩家名字可以在多個比賽中獲得多個分數(shù),但我只需要保留副本的最高分數(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.

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

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.

請?zhí)崆?/p>

推薦答案

你需要有一個函數(shù)來記錄每個玩家的最高分數(shù).如果還沒有玩家,它會將玩家添加到總數(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]

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

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

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區(qū)域周圍繪制一個矩形)
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(根據(jù)文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 亚洲欧美视频在线 | 久久久久免费视频 | 黄色网址在线免费观看 | 亚洲美女毛片 | 综合伊人久久 | 国产中文字幕在线播放 | 91看片看淫黄大片 | 亚洲黄色天堂 | 欧美精品网站 | 国产永久免费视频 | 国产一区不卡 | 国产综合自拍 | 伊人影院久久 | 亚洲精品国产精品国自产观看浪潮 | 婷婷亚洲综合 | 极品尤物一区二区三区 | 蜜臀久久99精品久久久久宅男 | 看片黄全部免费 | 欧美黄色一区二区 | av在线免费观看网站 | 青青伊人网 | 国产成人午夜精品 | 久久久午夜精品 | 人人插人人爽 | 黄色片视频在线观看 | 久久精品免费观看 | 国产综合亚洲精品一区二 | 欧美在线一区二区 | 欧美激情网址 | 少妇福利视频 | 亚洲国产精品久久久久久久 | 久久爱综合 | 中文字幕按摩做爰 | 福利视频午夜 | 福利一区福利二区 | 日韩av专区| 亚洲第一免费视频 | 亚洲天堂一区二区三区 | 一区二区视频在线播放 | 欧美精品色 | 一区二区不卡 |