abh - HTMLify profile

abh
501 Files
101798 Views
Latest files of /abh/def
def is_odd(n: int) -> bool:
if n == 1:
return True
if n == 0:
return False
return is_odd(n-2)
def is_odd(n: int) -> bool:
if n == 1:
return True
if n == 0:
return False
return is_odd(n-2)
def is_odd(n: int) -> bool:
def median(series):
s = series.copy()
s.sort()
n = len(s)
if n % 2 == 1:
return s[n // 2]
return (s[n//2]+s[(n//2)-1])/2
s = series.copy()
s.sort()
n = len(s)
if n % 2 == 1:
return s[n // 2]
return (s[n//2]+s[(n//2)-1])/2
def len(obj) -> int:
c = 0
while obj:
c += 1
obj = obj[1:]
return c
def len(obj) -> int:
c = 0
while obj:
c += 1
obj = obj[1:]
return c
def len(obj) -> int:
def roman_to_int(s):
romans = {'I': 1,
'V': 5,'X': 10,
'L': 50, 'C': 100,
'D': 500, 'M': 1000}
result = 0
prev_value = 0
for c in s[::-1]:
romans = {'I': 1,
'V': 5,'X': 10,
'L': 50, 'C': 100,
'D': 500, 'M': 1000}
result = 0
prev_value = 0
for c in s[::-1]:
def is_even(n: int) -> bool:
if n == 1:
return False
if n == 0:
return True
return is_even(n-2)
def is_even(n: int) -> bool:
if n == 1:
return False
if n == 0:
return True
return is_even(n-2)
def is_even(n: int) -> bool:
def digital_sum(n: int):
s = 0
while n:
s += n % 10
n //= 10
return s
def digital_sum(n: int):
s = 0
while n:
s += n % 10
n //= 10
return s
def digital_sum(n: int):
def average(*nums):
s = 0
c = 0
for n in nums:
s += n
c += 1
return s / c
s = 0
c = 0
for n in nums:
s += n
c += 1
return s / c
def is_happy(n: int):
n = str(n)
while len(n) != 1:
s = 0
for d in n:
s += int(d)*int(d)
n = str(s)
return n in "17"
n = str(n)
while len(n) != 1:
s = 0
for d in n:
s += int(d)*int(d)
n = str(s)
return n in "17"
# ABHDEF
This is a series of function which I started through my instagram account [@abh.py](https://www.instagram.com/abh.py) all the function of that series you can find in this repositry.
All the functions are written in python, and tested too but still if you find any bug or you have a better approch for the function then feel free to open an issue.
## Hope You like my functions ;)
## Functions currently in ABHDEF
This is a series of function which I started through my instagram account [@abh.py](https://www.instagram.com/abh.py) all the function of that series you can find in this repositry.
All the functions are written in python, and tested too but still if you find any bug or you have a better approch for the function then feel free to open an issue.
## Hope You like my functions ;)
## Functions currently in ABHDEF
def lower(s: str) -> str:
u = "QWERTYUIOPASDFGHJKLZXCVBNM"
l = "qwertyuiopasdfghjklzxcvbnm"
for c in s:
if c in u:
s = s.replace(c, l[u.find(c)])
return s
u = "QWERTYUIOPASDFGHJKLZXCVBNM"
l = "qwertyuiopasdfghjklzxcvbnm"
for c in s:
if c in u:
s = s.replace(c, l[u.find(c)])
return s
def is_valid_email(email):
parts = email.split("@")
if len(parts) == 2:
username, domain = parts
if username and domain:
if "." in domain:
return True
return False
parts = email.split("@")
if len(parts) == 2:
username, domain = parts
if username and domain:
if "." in domain:
return True
return False
def is_armstrong(n: int):
n = str(n)
p = len(n)
s = 0
for d in n:
s += int(d)**p
return int(n) == s
n = str(n)
p = len(n)
s = 0
for d in n:
s += int(d)**p
return int(n) == s
#Check the given string, number or list is palindrome or not.
def is_palindrome(n: int) -> bool:
r = 0
t = n
while n > 0:
r = r * 10 + n % 10
n //= 10
def is_palindrome(n: int) -> bool:
r = 0
t = n
while n > 0:
r = r * 10 + n % 10
n //= 10
def is_leap_year(year):
if not year % 100:
return not year % 400
return not year % 4
if not year % 100:
return not year % 400
return not year % 4
def mode(numbers):
if not numbers:
return []
mode = []
max_count = 0
for num in numbers:
count = numbers.count(num)
if count > max_count:
if not numbers:
return []
mode = []
max_count = 0
for num in numbers:
count = numbers.count(num)
if count > max_count:
#Calculate the factorial of given number
def factorial(n: int) -> int:
if n == 0:
return 1
return factorial(n-1) * n
def factorial(n: int) -> int:
def factorial(n: int) -> int:
if n == 0:
return 1
return factorial(n-1) * n
def factorial(n: int) -> int:
def sum(*nums):
s = 0
for i in nums:
s += i
return s
def sum(*nums: int):
s = 0
s = 0
for i in nums:
s += i
return s
def sum(*nums: int):
s = 0
def sqrt(n):
return n ** 0.5
def sqrt(n):
return n ** (1/2)
def sqrt(n :int):
i = 0
return n ** 0.5
def sqrt(n):
return n ** (1/2)
def sqrt(n :int):
i = 0
def lcm(a: int, b: int) -> int:
max = a if a > b else b
while True:
if not (max % a and max % b):
return max
max += 1
def lcm(a: int, b: int, max=None):
max = a if a > b else b
while True:
if not (max % a and max % b):
return max
max += 1
def lcm(a: int, b: int, max=None):
def upper(s: str) -> str:
u = "QWERTYUIOPASDFGHJKLZXCVBNM"
l = "qwertyuiopasdfghjklzxcvbnm"
for c in s:
if c in l:
s = s.replace(c, u[l.find(c)])
return s
u = "QWERTYUIOPASDFGHJKLZXCVBNM"
l = "qwertyuiopasdfghjklzxcvbnm"
for c in s:
if c in l:
s = s.replace(c, u[l.find(c)])
return s
def npr(n, r):
return factorial(n) // factorial(n-r)
def npr(n, r):
result = 1
for i in range(r):
result *= n - i
return result
return factorial(n) // factorial(n-r)
def npr(n, r):
result = 1
for i in range(r):
result *= n - i
return result
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def gcd(a, b):
while b:
a, b = b, a % b
if b == 0:
return a
return gcd(b, a % b)
def gcd(a, b):
while b:
a, b = b, a % b
def ncr(n, r):
numerator = 1
denominator = 1
for i in range(r):
numerator *= n - i
denominator *= i + 1
return numerator // denominator
numerator = 1
denominator = 1
for i in range(r):
numerator *= n - i
denominator *= i + 1
return numerator // denominator
def encrypt_rot13(text):
cipher = ""
for char in text:
if char.isalpha():
offset = 65 if char.isupper() else 97
cipher += chr((ord(char) - offset + 13) % 26 + offset)
else:
cipher += char
cipher = ""
for char in text:
if char.isalpha():
offset = 65 if char.isupper() else 97
cipher += chr((ord(char) - offset + 13) % 26 + offset)
else:
cipher += char
def encrypt_caesar_cipher(text, shift):
cipher = ""
for char in text:
if char.isalpha():
offset = 65 if char.isupper() else 97
cipher += chr((ord(char) - offset + shift) % 26 + offset)
else:
cipher += char
cipher = ""
for char in text:
if char.isalpha():
offset = 65 if char.isupper() else 97
cipher += chr((ord(char) - offset + shift) % 26 + offset)
else:
cipher += char
def encrypt_xor_cipher(text, key):
cipher = ""
for char in text:
cipher += chr(ord(char) ^ key)
return cipher
cipher = ""
for char in text:
cipher += chr(ord(char) ^ key)
return cipher
def char_frequency(string):
freq = {}
for c in string:
freq[c] = freq.get(c,0)+1
return freq
freq = {}
for c in string:
freq[c] = freq.get(c,0)+1
return freq
def word_frequency(text: str) -> dict:
words = text.split()
word_f = {}
for word in words:
w = word.strip(".,!?").lower()
word_f[w] = word_f.get(w,0)+1
return word_f
words = text.split()
word_f = {}
for word in words:
w = word.strip(".,!?").lower()
word_f[w] = word_f.get(w,0)+1
return word_f
def are_anagrams(s1, s2):
if len(s1) != len(s2):
return False
for c in s1:
if s1.count(c) != s2.count(c):
return False
return True
if len(s1) != len(s2):
return False
for c in s1:
if s1.count(c) != s2.count(c):
return False
return True
def is_pangram(text):
letters = "abcdefghijklmnopqrstuvwxyz"
for char in text:
if not char.lower() in letters:
return False
return True
def is_pangram(text):
letters = "abcdefghijklmnopqrstuvwxyz"
for char in text:
if not char.lower() in letters:
return False
return True
def is_pangram(text):
def is_isogram(s):
s = s.lower()
for c in s:
if s.count(c) > 1:
return False
return True
def is_isogram(s):
s = s.lower()
for c in s:
if s.count(c) > 1:
return False
return True
def is_isogram(s):
def is_vowel(char):
vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
return char in vowels
def is_vowel(char):
vowels = ["a", "e", "i", "o", "u"]
return char.lower() in vowels
vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
return char in vowels
def is_vowel(char):
vowels = ["a", "e", "i", "o", "u"]
return char.lower() in vowels
def is_consonant(char):
consonants = [
"b", "c", "d", "f", "g", "h",
"j", "k", "l", "m", "n", "p",
"q", "r", "s", "t", "v", "w",
"x", "y", "z", "B", "C", "D",
"F", "G", "H", "J", "K", "L",
"M", "N", "P", "Q", "R", "S",
consonants = [
"b", "c", "d", "f", "g", "h",
"j", "k", "l", "m", "n", "p",
"q", "r", "s", "t", "v", "w",
"x", "y", "z", "B", "C", "D",
"F", "G", "H", "J", "K", "L",
"M", "N", "P", "Q", "R", "S",
def is_prime(n):
if n < 2:
return False
devisors = 0
for i in range(1, n+1):
if n % i == 0:
devisors += 1
return devisors < 3
if n < 2:
return False
devisors = 0
for i in range(1, n+1):
if n % i == 0:
devisors += 1
return devisors < 3
def triangle_number(n):
t = 0
for i in range(1, n+1):
t += i
return t
def triangle_number(n):
return sum(range(1, n+1))
t = 0
for i in range(1, n+1):
t += i
return t
def triangle_number(n):
return sum(range(1, n+1))
def is_perfect_square(n):
sqrt = int(n ** 0.5)
return sqrt * sqrt == n
sqrt = int(n ** 0.5)
return sqrt * sqrt == n
def divisors(n: int):
ds = []
for i in range(1, n+1):
if not n % i:
ds.append(i)
return ds
def divisors(n: int):
ds = []
for i in range(1, n+1):
if not n % i:
ds.append(i)
return ds
def divisors(n: int):