只获取密钥但索引产生错误

时间:2017-12-05 17:34:50

标签: python dictionary

def swiss_pairings(self):
    players = self.player_standings()
    players_paired = []
    i = 0
    //  name = players.keys()[i]
    match_player = 1
    while match_player < range(len(players)):
        //  name_match_player = players.keys()[match_player]
        player_one_id = Player.objects.get(name=name)
        player_two_id = Player.objects.get(
            name=name_match_player)
        if self.has_played_before(player_one_id, player_two_id):
            match_player += 1
        else:
            self.report_match(player_one_id, player_two_id)
            players_paired.append(player_one_id.name, player_two_id.name)
            del players[name]
            del players[name_match_player]
            break
    return players_paired

注释行正在产生字典未编入索引。什么可以替代这两条线?我只想要“钥匙”。

0 个答案:

没有答案