• Nov 19, 2022 •CodeCatch
0 likes • 1 view
# Python code to find the URL from an input string # Using the regular expression import re def Find(string): # findall() has been used # with valid conditions for urls in string regex = r"(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’]))" url = re.findall(regex,string) return [x[0] for x in url] # Driver Code string = 'My Profile: https://codecatch.net' print("Urls: ", Find(string))
def key_of_min(d): return min(d, key = d.get) key_of_min({'a':4, 'b':0, 'c':13}) # b
• Dec 24, 2025 •CodeCatch
1 like • 4 views
def counting_sort(arr, exp): n = len(arr) output = [0] * n count = [0] * 10 for i in range(n): index = (arr[i] // exp) % 10 count[index] += 1 for i in range(1, 10): count[i] += count[i-1] i = n - 1 while i >= 0: index = (arr[i] // exp) % 10 output[count[index] - 1] = arr[i] count[index] -= 1 i -= 1 for i in range(n): arr[i] = output[i] def radix_sort(arr): max_val = max(arr) exp = 1 while max_val // exp > 0: counting_sort(arr, exp) exp *= 10 if __name__ == "__main__": arr = [170, 45, 75, 90, 802, 24, 2, 66] print("Original array:", arr) radix_sort(arr) print("Sorted array:", arr)
• Mar 10, 2021 •Skrome
0 likes • 2 views
color2 = (60, 74, 172) color1 = (19, 28, 87) percent = 1.0 for i in range(101): resultRed = round(color1[0] + percent * (color2[0] - color1[0])) resultGreen = round(color1[1] + percent * (color2[1] - color1[1])) resultBlue = round(color1[2] + percent * (color2[2] - color1[2])) print((resultRed, resultGreen, resultBlue)) percent -= 0.01
• May 31, 2023 •CodeCatch
0 likes • 0 views
# Function to check Armstrong number def is_armstrong_number(number): # Convert number to string to iterate over its digits num_str = str(number) # Calculate the sum of the cubes of each digit digit_sum = sum(int(digit) ** len(num_str) for digit in num_str) # Compare the sum with the original number if digit_sum == number: return True else: return False # Prompt user for a number number = int(input("Enter a number: ")) # Check if the number is an Armstrong number if is_armstrong_number(number): print(number, "is an Armstrong number.") else: print(number, "is not an Armstrong number.")
• Jan 20, 2021 •Ntindle
0 likes • 5 views
print(“Hello World”)