Ad
Code
Diff
  • def kata(a, b):
        return a * b
    
    
    • Kata=lambda x,y: x*y
    • def kata(a, b):
    • return a * b
    • # Alternative:
    • # def Kata(string, num):
    • # return string*num
Fundamentals
Arrays
Strings
Code
Diff
  • find_trex = lambda x: x.__contains__('Tyrannosaurus')
    • def find_trex(lst):
    • return 'Tyrannosaurus' in lst
    • find_trex = lambda x: x.__contains__('Tyrannosaurus')
Code
Diff
  • class IsEqual:
        def __init__(self, k):
            self.k = k
    
        def __eq__(self, other):
            return ['yes', 'no'][self.k != other.k]
    • class IsEqual:
    • def __init__(self, k):
    • self.k = k
    • def __eq__(self, other):
    • return ['no', 'yes'][self.k == other.k]
    • return ['yes', 'no'][self.k != other.k]
Code
Diff
  • power = lambda n, p: pow(n, p)
    • def power(n, p):
    • return pow(n, p)
    • power = lambda n, p: pow(n, p)
Code
Diff
  • def power(n, p):
        return pow(n, p)
    
    • def power(num, p):
    • return num ** p
    • def power(n, p):
    • return pow(n, p)
Code
Diff
  • def replicate(t, n):
        return [] if t <= 0 else [n]+replicate(t-1,n)
    
    • def replicate(times, num):
    • if times<=0:
    • return []
    • else:
    • return [num]+replicate(times-1,num)
    • print(replicate(8,5))
    • def replicate(t, n):
    • return [] if t <= 0 else [n]+replicate(t-1,n)