-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem414.py
More file actions
executable file
·29 lines (27 loc) · 896 Bytes
/
problem414.py
File metadata and controls
executable file
·29 lines (27 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def listify(string):
list = []
for char in string:
if char != ' ' and char != '[' and char != ']' and char != ',':
list.append(int(char))
return list
def thirdMax(list):
first_max = None
second_max = None
third_max = None
for member in list:
if member > first_max:
third_max = second_max
second_max = first_max
first_max = member
elif member > second_max and first_max != member:
third_max = second_max
second_max = member
elif member > third_max and second_max != member and first_max != member:
third_max = member
if third_max == None:
return first_max
return third_max
if __name__ == '__main__':
string_list = raw_input("Enter a list (ex. [3,2,1]): ")
list = listify(string_list)
print("Output: %d") % (thirdMax(list))