class athlete:
def __init__(self, path):
with open(path) as timef:
temp = timef.readline()
self.data = temp.strip().split(',')
def sort_time(self):
clean_data = []
for time in self.data:
if '-' in time:
splitter = '-'
elif ':' in time:
splitter = ':'
else:
splitter = '.'
(mins, secs) = time.split(splitter)
clean_data.append(mins + '.' + secs)
return sorted(set(clean_data))[0:3]
if __name__ == '__main__':
james = athlete('./data/james.txt')
julie = athlete('./data/julie.txt')
mikey = athlete('./data/mikey.txt')
sarah = athlete('./data/sarah.txt')
print(james.sort_time())
print(julie.sort_time())
print(mikey.sort_time())
print(sarah.sort_time())
Head First Python Notes - Chapter 5
最新推荐文章于 2019-11-27 11:29:22 发布