Skip to main content

Binary search algorithm

0 likes • Nov 19, 2022 • 0 views
Python
Loading...

More Python Posts

Caesar Encryption

0 likes • Mar 10, 2021 • 0 views
Python
import string
def caesar(text, shift, alphabets):
def shift_alphabet(alphabet):
return alphabet[shift:] + alphabet[:shift]
shifted_alphabets = tuple(map(shift_alphabet, alphabets))
final_alphabet = "".join(alphabets)
final_shifted_alphabet = "".join(shifted_alphabets)
table = str.maketrans(final_alphabet, final_shifted_alphabet)
return text.translate(table)
plain_text = "Hey Skrome, welcome to CodeCatch"
print(caesar(plain_text, 8, [string.ascii_lowercase, string.ascii_uppercase, string.punctuation]))

Finding NULL values within set

0 likes • Oct 7, 2022 • 1 view
Python
x[cat_var].isnull().sum().sort_values(ascending=False)

Copy file to destination

0 likes • Nov 18, 2022 • 1 view
Python
# 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())

Hello, python

0 likes • Jan 20, 2021 • 2 views
Python
print(“Hello World”)

hex to rgb

0 likes • Nov 19, 2022 • 2 views
Python
def hex_to_rgb(hex):
return tuple(int(hex[i:i+2], 16) for i in (0, 2, 4))
hex_to_rgb('FFA501') # (255, 165, 1)

LeetCode Flood Fill

0 likes • Oct 15, 2022 • 0 views
Python
class Solution(object):
def floodFill(self, image, sr, sc, newColor):
R, C = len(image), len(image[0])
color = image[sr][sc]
if color == newColor: return image
def dfs(r, c):
if image[r][c] == color:
image[r][c] = newColor
if r >= 1: dfs(r-1, c)
if r+1 < R: dfs(r+1, c)
if c >= 1: dfs(r, c-1)
if c+1 < C: dfs(r, c+1)
dfs(sr, sc)
return image