Ejemplo n.º 1
0
 def top3(self):
     return sorted(set([CommonUtils.sanitize(t) for t in self.times]))[0:3]
Ejemplo n.º 2
0
path3 = file_dir + "L6_sarah.txt"

# 读取数据
james = CommonUtils.load_data(path0).strip().split(',')
julie = CommonUtils.load_data(path1).strip().split(',')
mikey = CommonUtils.load_data(path2).strip().split(',')
sarah = CommonUtils.load_data(path3).strip().split(',')

print(sorted(CommonUtils.deal_data(james)))
print(sorted(CommonUtils.deal_data(julie)))
print(sorted(CommonUtils.deal_data(mikey)))
print(sorted(CommonUtils.deal_data(sarah)))

# 推到表方式转换数据
print("\n\n列表推导:")
clean_james = sorted([CommonUtils.sanitize(item) for item in james])
print(clean_james)

# 排除重复,并取最大的三个数据
james_1 = sorted([CommonUtils.sanitize(item) for item in james])
unique_james = []
for item in james_1:
    if item not in unique_james:
        unique_james.append(item)

print("\n\n排除重复,并取最大的三个数据:")
print(unique_james[0:3])

#使用集合方式
james = CommonUtils.deal_data(james)
print("\n\n集合方式:")