TypeError:unorderable类型:dict()>字典()

时间:2016-11-14 15:48:52

标签: python sorting dictionary

我必须使用任何排序功能排序权重。

class sample:
    counter = 0
    record=[{"studentname":"akshay", "studentid":"17905", "roomnum":"123", "height":"5.0","weight":"155"},
           {"studentname":"naveen", "studentid":"1234", "roomnum":"45", "height":"5.5", "weight":"146"},
           {"studentname":"rahul", "studentid":"34", "roomnum":"23", "height":"6.7", "weight":"170"},
           {"studentname":"kiran", "studentid":"45", "roomnum":"43", "height":"5.8", "weight":"176"},
           {"studentname":"sai", "studentid":"56", "roomnum":"12", "height":"5.9", "weight":"173"},
           {"studentname":"giri", "studentid":"63", "roomnum":"65", "height":"6.1", "weight":"143"},
           {"studentname":"pranoy", "studentid":"46", "roomnum":"56", "height":"6.8", "weight":"123"},
           {"studentname":"phani", "studentid":"58", "roomnum":"23", "height":"6.2", "weight":"321"},
           {"studentname":"nihar", "studentid":"37", "roomnum":"29", "height":"5.4", "weight":"43"},
           {"studentname":"hitesh", "studentid":"45", "roomnum":"33", "height":"5.6", "weight":"145"}]
    def __init__(self, studentname, studentid, roomnum, height, weight):
        type(self).counter +=1
        self.studentname = studentname
        self.studentid = studentid
        self.roomnum = roomnum
        self.height = height
        self.weight = weight

       def PrintAllStudentsInWeight():
        for i in range(len('weight')):
            weight = sample.record
            for j in range(len('weight') -1):
                if weight[j] > weight[j+1]:
                   weight[j+1] = weight[j] = weight[j], weight[j+1]
                   print(weight)
PrintAllStudentsInWeight()    

;请帮助,我是python的新手。

0 个答案:

没有答案