-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_annotations.py
More file actions
62 lines (48 loc) · 1.4 KB
/
Copy pathfunction_annotations.py
File metadata and controls
62 lines (48 loc) · 1.4 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def is_int(x):
return isinstance(x, int)
def f(ham: is_int, eggs: str = 'eggs') -> str:
print("Annotations:", f.__annotations__)
print("Arguments:", ham, eggs)
return (str(ham) + ' and ' + eggs)
what = f('spam')
why = f(2)
print(what, type(what), why)
def merge_sort():
'''
Merge sort is a recursive algorithm that works by breaking down a list into smaller lists,
then merging those smaller lists into larger, sorted lists.
'''
def merge_sort_iterative(items):
'''
Merge sort implementation
'''
def merge_sort_recursive(items):
'''
Merge sort is a recursive algorithm that works by breaking down a list into smaller lists,
then merging those smaller lists into larger, sorted lists.
'''
if len(items) > 1:
mid = len(items) // 2
left = items[:mid]
right = items[mid:]
merge_sort_recursive(left)
merge_sort_recursive(right)
i = 0
j = 0
k = 0
while i < len(left) and j < len(right):
if left[i] < right[j]:
items[k] = left[i]
i += 1
else:
items[k] = right[j]
j += 1
k += 1
while i < len(left):
items[k] = left[i]
i += 1
k += 1
while j < len(right):
items[k] = right[j]
j += 1
k += 1