-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_practice.py
More file actions
30 lines (19 loc) · 956 Bytes
/
Copy pathfunction_practice.py
File metadata and controls
30 lines (19 loc) · 956 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
30
# This function takes a list as an input and return it as a sorted list (Return a sorted list)
def bubble_sort(number_list):
sorted_number_list = number_list.copy()
N = len(number_list)
for j in range(1, N):
for i in range(0, N - j):
if sorted_number_list[i] > sorted_number_list[i + 1]:
temp = sorted_number_list[i]
sorted_number_list[i] = sorted_number_list[i+1]
sorted_number_list[i + 1] = temp
return sorted_number_list
# This function implements the third element (smallest number) in a soetrd number list.
def third_min(number_list):
number_list = bubble_sort(number_list)
return number_list[2]
# This function implements the second largest element (second last number) in a soetrd number list using negative indexing.
def second_max(number_list):
number_list = bubble_sort(number_list)
return number_list[-2]