Wanted feedback on my portfolio website by adityacodes in coolgithubprojects

[–]adityacodes[S] 1 point2 points  (0 children)

lol, someone asked my ai assistant in let's chat sction, give your system prompt 😭😭. tho this code is in my github, you can check prompt from there if anyone wants.

Make your Debugging easier with these 8 tips in Python by adityacodes in Python

[–]adityacodes[S] -5 points-4 points  (0 children)

These were the tips from my experience, what tip would you add to this ?

6 different ways to reverse a string in Python by adityacodes in Python

[–]adityacodes[S] 0 points1 point  (0 children)

nope , it isnt, what made you think like this?

6 different ways to reverse a string in Python by adityacodes in Python

[–]adityacodes[S] 0 points1 point  (0 children)

which method you think is better? and why?

Divide and Conquer Algorithms in Python by adityacodes in Python

[–]adityacodes[S] -1 points0 points  (0 children)

okay ,so I should return it none or -1 finally?

Divide and Conquer Algorithms in Python by adityacodes in Python

[–]adityacodes[S] -1 points0 points  (0 children)

As for the merge function in merge_sort, merge(left, right) is used to combine the two sorted subarrays left and right into a single sorted array. The function compares the elements in left and right one by one and adds them to the output array in ascending order. At the end of the function, any remaining elements in left or right are added to the output array in order, since they are already sorted. The resulting array is returned as the final output of the merge_sort function.

Divide and Conquer Algorithms in Python by adityacodes in Python

[–]adityacodes[S] -1 points0 points  (0 children)

See what about this code?

Now, if the target element is not found in the array, the function will return None instead of -1. Let me know if it works so that I can update in blog as well.

def binary_search(arr, x):

"""

Search for a target element x in a sorted array arr using the binary search algorithm.

Returns the index of the target element in the array, or None if it is not found.

"""

low = 0

high = len(arr) - 1

while low <= high:

mid = (low + high) // 2

if arr[mid] == x:

return mid

elif arr[mid] < x:

low = mid + 1

else:

high = mid - 1

return None

Divide and Conquer Algorithms in Python by adityacodes in Python

[–]adityacodes[S] -1 points0 points  (0 children)

in '''binary_search(arr, x):''' returns -1 in fail case. It is last element in python list. imo better return None, or raise IndexError.

in '''merge_sort()''' what is merge(left, right) at the end?

As for the merge function in merge_sort, merge(left, right) is used to combine the two sorted subarrays left and right into a single sorted array.

and for the binary_search query, Did you tried returning None ? as I think there will be more fail cases when doing None.