• Oct 15, 2022 •CodeCatch
1 like • 2 views
my_list = ["blue", "red", "green"] #1- Using sort or srted directly or with specifc keys my_list.sort() #sorts alphabetically or in an ascending order for numeric data my_list = sorted(my_list, key=len) #sorts the list based on the length of the strings from shortest to longest. # You can use reverse=True to flip the order #2- Using locale and functools import locale from functools import cmp_to_key my_list = sorted(my_list, key=cmp_to_key(locale.strcoll))
• Nov 18, 2022 •AustinLeath
0 likes • 1 view
# importing the modules import os import shutil # getting the current working directory src_dir = os.getcwd() # printing current directory print(src_dir) # copying the files shutil.copyfile('test.txt', 'test.txt.copy2') #copy src to dst # printing the list of new files print(os.listdir())
• Aug 1, 2025 •AustinLeath
0 likes • 2 views
import re _proposal_regex = r'(?:(?:(IKE|ESP):)?[\w/]+(?:/NO_EXT_SEQ)?(?:, ?(IKE|ESP):[\w/]+(?:/NO_EXT_SEQ)?)*)?' _proposals_re = rf'(?P<proposals>{_proposal_regex}|)' pattern = rf'received proposals: {_proposals_re}' match = re.match(pattern, 'received proposals: ') print(match.group('proposals') if match else "No match") # Prints "No match"
• Oct 4, 2023 •AustinLeath
0 likes • 10 views
weigh = lambda a,b: sum(b)-sum(a) FindCoin = lambda A: 0 if (n := len(A)) == 1 else (m := n//3) * (w := 1 + weigh(A[:m], A[2*m:])) + FindCoin(A[m*w:m*(w+1)]) print(FindCoin([1,1,1,1,1,1,1,2,1]))
• Apr 21, 2023 •sebastianagauyao2002-61a8
0 likes • 3 views
print("hellur")
• 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.")