这是我到目前为止编写的代码,程序的重点是从文件中读取 20 个人,然后分配他们的属性,然后根据用户给出的输入规范化他们的值。
class One:
def __init__(self):
self.attrOne = ()
self.attrTwo = ()
self.attrThree = ()
self.attrFour = ()
self.attrFive= ()
self.attrSix = ()
self.attrSeven = ()
self.attrEight = ()
self.attrNine = ()
class Two:
def __init__(self):
self.allPersons = []
def importFromList(self, filename):
file= open(filename, "rU")
for line in file:
partOfList = line.split()
x = Partner()
x.attrOne = partOfList[0]
x.attrTwo = partOfList[1]
x.attrThree = partOfList[2]
x.attrFour = partOfList[3]
x.attrFive = partOfList[4]
x.attrSix = partOfList[5]
x.attrSeven = partOfList[6]
x.attrEight= partOfList[7]
x.attrNine = partOfList[8]
self.addPerson(x)
file.close()
def addPerson(self, x):
self.allPersons.append(x)
我想知道的是如何遍历放在 allPersons 列表中的人员的属性,然后将它们相互比较以找出最大值。这是我到目前为止尝试过的,但我无法让它工作
def getMaxValue(self):
o = One()
for eachPartner in self.allPartners:
maxValuesAttrOne = max(O.attrOne))
所有帮助将不胜感激,我对新的解决方案持开放态度,而且我认为 importFromList 方法不是最有效的方法,所以如果您有任何异议,我愿意倾听和学习!