|
@@ -666,12 +666,82 @@ nes = {'Germany': {'berlin': 7},
|
|
|
'USA': {'washington': 1, 'New York': 4}}
|
|
|
|
|
|
|
|
|
-print(flatten_dict({'Q': {'w': {'E': {'r': {'T': {'y': 123}}}}}}))
|
|
|
+
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
|
def merge_two_list(a, b):
|
|
|
- pass
|
|
|
+ c = []
|
|
|
+ i = j = 0
|
|
|
+ while i < len(a) and j < len(b):
|
|
|
+ if a[i] < b[j]:
|
|
|
+ c.append(a[i])
|
|
|
+ i += 1
|
|
|
+ else:
|
|
|
+ c.append(b[j])
|
|
|
+ j += 1
|
|
|
+ if i < len(a):
|
|
|
+ c += a[i:]
|
|
|
+ elif j < len(b):
|
|
|
+ c += b[j:]
|
|
|
+ return c
|
|
|
+
|
|
|
|
|
|
def merge_sort(s):
|
|
|
- pass
|
|
|
+ if len(s) == 1:
|
|
|
+ return s
|
|
|
+ middle = len(s)//2
|
|
|
+ left = merge_sort(s[:middle])
|
|
|
+ right = merge_sort(s[middle:])
|
|
|
+ return merge_two_list(left, right)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+def quick_sort(s):
|
|
|
+ if len(s) <= 1:
|
|
|
+ return s
|
|
|
+
|
|
|
+ elem = s[0]
|
|
|
+ left = list(filter(lambda x: x < elem, s))
|
|
|
+ center = [i for i in s if i == elem]
|
|
|
+ right = list(filter(lambda x: x > elem, s))
|
|
|
+
|
|
|
+ return quick_sort(left) + center + quick_sort(right)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|