Loading...
More Python Posts
from math import pidef rads_to_degrees(rad):return (rad * 180.0) / pirads_to_degrees(pi / 2) # 90.0
# Python program for implementation of Selection# Sortimport sysA = [64, 25, 12, 22, 11]# Traverse through all array elementsfor i in range(len(A)):# Find the minimum element in remaining# unsorted arraymin_idx = ifor j in range(i+1, len(A)):if A[min_idx] > A[j]:min_idx = j# Swap the found minimum element with# the first elementA[i], A[min_idx] = A[min_idx], A[i]# Driver code to test aboveprint ("Sorted array")for i in range(len(A)):print("%d" %A[i]),
magnitude = lambda bits: 1_000_000_000_000_000_000 % (2 ** bits)sign = lambda bits: -1 ** (1_000_000_000_000_000_000 // (2 ** bits))print("64 bit sum:", magnitude(64) * sign(64))print("32 bit sum:", magnitude(32) * sign(32))print("16 bit sum:", magnitude(16) * sign(16))
def print_x_pattern(size):i,j = 0,size - 1while j >= 0 and i < size:initial_spaces = ' '*min(i,j)middle_spaces = ' '*(abs(i - j) - 1)final_spaces = ' '*(size - 1 - max(i,j))if j == i:print(initial_spaces + '*' + final_spaces)else:print(initial_spaces + '*' + middle_spaces + '*' + final_spaces)i += 1j -= 1print_x_pattern(7)
from collections import Counterdef find_parity_outliers(nums):return [x for x in numsif x % 2 != Counter([n % 2 for n in nums]).most_common()[0][0]]find_parity_outliers([1, 2, 3, 4, 6]) # [1, 3]
https://codecatch.net/post/06c9f5b7-1e00-40dc-b436-b8cccc4b69be