recursive implementation.
3rd return -> num ^ p = (num ^ 2) ^ (p / 2)
def power(num, p): assert p >= 0 if num == 0 or p == 0: return int(num != 0) if p % 2: return power(num, p - 1) * num return power(num * num, p // 2)
def power(num1, num2):return num1**num2number_1 = 2number_2 = 5power(number_1, number_2)- def power(num, p):
- assert p >= 0
- if num == 0 or p == 0:
- return int(num != 0)
- if p % 2:
- return power(num, p - 1) * num
- return power(num * num, p // 2)
def remove(integers, values): values = set(values) return list(filter(lambda element: element not in values, integers))
- def remove(integers, values):
value_set = set(values)res = []for x in integers:if x not in value_set:res += [x]return res- values = set(values)
- return list(filter(lambda element: element not in values, integers))
def find_first_sub_string(text: str, sub: str): index = text.find(sub) return index if index != -1 else None
def find_first_sub_string(text, sub):try: return text.index(sub)except: pass- def find_first_sub_string(text: str, sub: str):
- index = text.find(sub)
- return index if index != -1 else None