diff options
Diffstat (limited to 'progs')
| -rw-r--r-- | progs/a284.py | 24 | ||||
| -rw-r--r-- | progs/a339.py | 51 | ||||
| -rw-r--r-- | progs/a394.py | 46 | ||||
| -rw-r--r-- | progs/a403.py | 2 | ||||
| -rw-r--r-- | progs/a52.py | 14 | ||||
| -rw-r--r-- | progs/a641.py | 12 | ||||
| -rw-r--r-- | progs/a745.py | 32 | 
7 files changed, 97 insertions, 84 deletions
diff --git a/progs/a284.py b/progs/a284.py index b69395b..cfd429d 100644 --- a/progs/a284.py +++ b/progs/a284.py @@ -1,11 +1,13 @@ -def is_Isomorphic(str1,str2):          
 -    dict_str1 = {}
 -    dict_str2 = {}
 -    for i, value in enumerate(str1):
 -        dict_str1[value] = dict_str1.get(value,[]) + [i]        
 -    for j, value in enumerate(str2):
 -        dict_str2[value] = dict_str2.get(value,[]) + [j]
 -    if sorted(dict_str1.values()) == sorted(dict_str2.values()):
 -        return True
 -    else:
 -        return False
\ No newline at end of file +# FIXME: multiple variable assignment in for loop
 +#
 +# def is_Isomorphic(str1,str2):          
 +#     dict_str1 = {}
 +#     dict_str2 = {}
 +#     for i, value in enumerate(str1):
 +#         dict_str1[value] = dict_str1.get(value,[]) + [i]        
 +#     for j, value in enumerate(str2):
 +#         dict_str2[value] = dict_str2.get(value,[]) + [j]
 +#     if sorted(dict_str1.values()) == sorted(dict_str2.values()):
 +#         return True
 +#     else:
 +#         return False
\ No newline at end of file diff --git a/progs/a339.py b/progs/a339.py index 9a57403..95724d2 100644 --- a/progs/a339.py +++ b/progs/a339.py @@ -1,25 +1,28 @@ -def heap_sort(arr):
 -    heapify(arr)  
 -    end = len(arr) - 1
 -    while end > 0:
 -        arr[end], arr[0] = arr[0], arr[end]
 -        shift_down(arr, 0, end - 1)
 -        end -= 1
 -    return arr
 +# FIXME: chiamata a funzione definita dopo
 +#
 +# def heap_sort(arr):
 +#     heapify(arr)  
 +#     end = len(arr) - 1
 +#     while end > 0:
 +#         arr[end], arr[0] = arr[0], arr[end]
 +#         shift_down(arr, 0, end - 1)
 +#         end -= 1
 +#     return arr
 -def heapify(arr):
 -    start = len(arr) // 2
 -    while start >= 0:
 -        shift_down(arr, start, len(arr) - 1)
 -        start -= 1
 -def shift_down(arr, start, end):
 -    root = start
 -    while root * 2 + 1 <= end:
 -        child = root * 2 + 1
 -        if child + 1 <= end and arr[child] < arr[child + 1]:
 -            child += 1
 -        if child <= end and arr[root] < arr[child]:
 -            arr[root], arr[child] = arr[child], arr[root]
 -            root = child
 -        else:
 -            return
 +# def heapify(arr):
 +#     start = len(arr) // 2
 +#     while start >= 0:
 +#         shift_down(arr, start, len(arr) - 1)
 +#         start -= 1
 +
 +# def shift_down(arr, start, end):
 +#     root = start
 +#     while root * 2 + 1 <= end:
 +#         child = root * 2 + 1
 +#         if child + 1 <= end and arr[child] < arr[child + 1]:
 +#             child += 1
 +#         if child <= end and arr[root] < arr[child]:
 +#             arr[root], arr[child] = arr[child], arr[root]
 +#             root = child
 +#         else:
 +#             return
 diff --git a/progs/a394.py b/progs/a394.py index 4fe6e47..25f8f3e 100644 --- a/progs/a394.py +++ b/progs/a394.py @@ -1,22 +1,24 @@ -def func(nums, k):
 -    import collections
 -    d = collections.defaultdict(int)
 -    for row in nums:
 -        for i in row:
 -            d[i] += 1
 -    temp = []
 -    import heapq
 -    for key, v in d.items():
 -        if len(temp) < k:
 -            temp.append((v, key))
 -            if len(temp) == k:
 -                heapq.heapify(temp)
 -        else:
 -            if v > temp[0][0]:
 -                heapq.heappop(temp)
 -                heapq.heappush(temp, (v, key))
 -    result = []
 -    while temp:
 -        v, key = heapq.heappop(temp)
 -        result.append(key)
 -    return result
\ No newline at end of file +# FIXME: multiple variable assignment in for loop
 +#
 +# def func(nums, k):
 +#     import collections
 +#     d = collections.defaultdict(int)
 +#     for row in nums:
 +#         for i in row:
 +#             d[i] += 1
 +#     temp = []
 +#     import heapq
 +#     for key, v in d.items():
 +#         if len(temp) < k:
 +#             temp.append((v, key))
 +#             if len(temp) == k:
 +#                 heapq.heapify(temp)
 +#         else:
 +#             if v > temp[0][0]:
 +#                 heapq.heappop(temp)
 +#                 heapq.heappush(temp, (v, key))
 +#     result = []
 +#     while temp:
 +#         v, key = heapq.heappop(temp)
 +#         result.append(key)
 +#     return result
\ No newline at end of file diff --git a/progs/a403.py b/progs/a403.py index 18c84b2..ee1bdd7 100644 --- a/progs/a403.py +++ b/progs/a403.py @@ -2,4 +2,4 @@ from collections import Counter  from itertools import chain
  def freq_element(nums):
    result = Counter(chain.from_iterable(nums))
 -  return result
\ No newline at end of file +  return result
 diff --git a/progs/a52.py b/progs/a52.py index 4a0b33a..1d116bc 100644 --- a/progs/a52.py +++ b/progs/a52.py @@ -1,6 +1,8 @@ -from collections import defaultdict
 -def grouping_dictionary(l):
 -    d = defaultdict(list)
 -    for k, v in l:
 -        d[k].append(v)
 -    return d
\ No newline at end of file +# FIXME: multiple variable assignment in for loop
 +#
 +# from collections import defaultdict
 +# def grouping_dictionary(l):
 +#     d = defaultdict(list)
 +#     for k, v in l:
 +#         d[k].append(v)
 +#     return d
\ No newline at end of file diff --git a/progs/a641.py b/progs/a641.py index 51393cd..52b0f6a 100644 --- a/progs/a641.py +++ b/progs/a641.py @@ -1,5 +1,7 @@ -def count_first_elements(test_tup):
 -  for count, ele in enumerate(test_tup):
 -    if isinstance(ele, tuple):
 -      break
 -  return (count) 
\ No newline at end of file +# FIXME: multiple variable assignment in for loop
 +#
 +# def count_first_elements(test_tup):
 +#   for count, ele in enumerate(test_tup):
 +#     if isinstance(ele, tuple):
 +#       break
 +#   return (count) 
\ No newline at end of file diff --git a/progs/a745.py b/progs/a745.py index 9a21dfa..e8ad671 100644 --- a/progs/a745.py +++ b/progs/a745.py @@ -1,15 +1,17 @@ -def find_rotation_count(A):
 -    (left, right) = (0, len(A) - 1)
 -    while left <= right:
 -        if A[left] <= A[right]:
 -            return left
 -        mid = (left + right) // 2
 -        next = (mid + 1) % len(A)
 -        prev = (mid - 1 + len(A)) % len(A)
 -        if A[mid] <= A[next] and A[mid] <= A[prev]:
 -            return mid
 -        elif A[mid] <= A[right]:
 -            right = mid - 1
 -        elif A[mid] >= A[left]:
 -            left = mid + 1
 -    return -1
\ No newline at end of file +# FIXME: unpacking assignment
 +#
 +# def find_rotation_count(A):
 +#     (left, right) = (0, len(A) - 1)
 +#     while left <= right:
 +#         if A[left] <= A[right]:
 +#             return left
 +#         mid = (left + right) // 2
 +#         next = (mid + 1) % len(A)
 +#         prev = (mid - 1 + len(A)) % len(A)
 +#         if A[mid] <= A[next] and A[mid] <= A[prev]:
 +#             return mid
 +#         elif A[mid] <= A[right]:
 +#             right = mid - 1
 +#         elif A[mid] >= A[left]:
 +#             left = mid + 1
 +#     return -1
\ No newline at end of file  |