'''
从list中取出最大的三个值
__author__:无名
'''
def FindList3MaxNum(foo):
max1, max2, max3 = None, None, None
for num in foo:
if max1 is None or max1 < num:
max1, num = num, max1
if num is None:
continue
if max2 is None or num > max2:
max2, num = num, max2
if num is None:
continue
if max3 is None or num > max3:
max3 = num
return max1, max2, max3
if __name__ == '__main__':
foo = [78, 23, 10, 56, 4, 103, 89, 14]
max1, max2, max3 = FindList3MaxNum(foo)
print(max1, max2, max3)
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |