Ad
Lists
Data Structures
Numbers
Data Types
Functions
Control Flow
Basic Language Features
Fundamentals
Algorithms
Logic
Code
Diff
  • def combine_list(list1,list2):
        return list(filter(lambda c: c > 0, set(list1 + list2)))
    • combine_list=lambda a,b:[x for x in set(a+b)if x>0]
    • def combine_list(list1,list2):
    • return list(filter(lambda c: c > 0, set(list1 + list2)))
Lists
Data Structures
Numbers
Data Types
Functions
Control Flow
Basic Language Features
Fundamentals
Algorithms
Logic
Code
Diff
  • def combine_list(list1,list2):
        return [x for x in set([*list1, *list2]) if x > 0]
    • def combine_list(list1,list2):
    • solution = set(x for x in list1 if x > 0)
    • solution.update(x for x in list2 if x > 0)
    • return list(solution)
    • return [x for x in set([*list1, *list2]) if x > 0]
Code
Diff
  • def is_prime(n: int) -> bool:
        if n < 5:
            return n in (2, 3)
        if not n & 1 or not n % 3:
            return False
        return not any(not n%i or not n%(i+2) for i in range(5, int(n**0.5) + 1, 6))
    • is_prime = lambda n: n == 2 or n > 2 and n % 2 and all(n % i for i in range(3, int(n**.5) + 1, 2))
    • def is_prime(n: int) -> bool:
    • if n < 5:
    • return n in (2, 3)
    • if not n & 1 or not n % 3:
    • return False
    • return not any(not n%i or not n%(i+2) for i in range(5, int(n**0.5) + 1, 6))
Code
Diff
  • def is_prime(n: int) -> bool:
        if n <= 1:
            return False
        if n <= 3:
            return True
        if n % 2 == 0 or n % 3 == 0:
            return False
        sqrtn: int = int(n**0.5) + 1
        for i in range(5, sqrtn, 6):
            if n % i == 0 or n % (i + 2) == 0:
                return False
        return True
    • export const checkIsNumberSimple = (number: number) => {
    • // Check if the number is integer
    • if (number % 1 != 0) return false;
    • if (number < 2) return false;
    • if (number != 2 && number % 2 == 0) return false;
    • if (number != 3 && number % 3 == 0) return false;
    • return true;
    • };
    • def is_prime(n: int) -> bool:
    • if n <= 1:
    • return False
    • if n <= 3:
    • return True
    • if n % 2 == 0 or n % 3 == 0:
    • return False
    • sqrtn: int = int(n**0.5) + 1
    • for i in range(5, sqrtn, 6):
    • if n % i == 0 or n % (i + 2) == 0:
    • return False
    • return True
Code
Diff
  • def remove(string):
        return ''.join(x for x in string if x.islower())
    
        
    • import string
    • def remove(string):
    • arr = list(string)
    • test = ""
    • for i in range (len(arr)):
    • if arr[i].isupper() == True or arr[i] in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] or arr[i] == " ":
    • arr[i] = "`"
    • else:
    • continue
    • for i in arr:
    • test += i
    • return(test.replace("`", ""))
    • return ''.join(x for x in string if x.islower())
Sorting
Algorithms
Logic

Added tests

Code
Diff
  • def sort_by_salary(workers):
        return tuple(x[0] for x in sorted([x for x in workers if x[1]!='-'], key=lambda x: int(x[1]), reverse=True)[:5])
    • def sort_by_salary(workers):
    • filtered = list(filter(lambda x: x[1] != "-", workers))
    • if not filtered:
    • return tuple()
    • new = list(sorted(filtered, key=lambda x: int(x[1])))[::-1]
    • return tuple(i[0] for i in new)[:5]
    • return tuple(x[0] for x in sorted([x for x in workers if x[1]!='-'], key=lambda x: int(x[1]), reverse=True)[:5])
Code
Diff
  • from itertools import accumulate
    from operator import mul
    
    def prod(arr):
        if arr:
            for x in accumulate(arr, mul):
                pass
            return x
        return 1
    • from math import prod
    • from itertools import accumulate
    • from operator import mul
    • def prod(arr):
    • if arr:
    • for x in accumulate(arr, mul):
    • pass
    • return x
    • return 1
Code
Diff
  • import heapq
    def find_max(arr):
        arr = [-x for x in arr]
        heapq.heapify(arr)    
        return -arr[0]
    • def find_max(arr) : return max(arr)
    • import heapq
    • def find_max(arr):
    • arr = [-x for x in arr]
    • heapq.heapify(arr)
    • return -arr[0]
Code
Diff
  • def flip_the_number(n):
        return int(f'{n}'[::-1])
    • def flip_the_number(n):
    • return int(str(n)[::-1])
    • return int(f'{n}'[::-1])
Code
Diff
  • def flip_the_number(n):
        # takes int, flips int, return int
        r = 0
        while n > 0:
            r *= 10
            r += n % 10
            n //= 10
        return r
    • def flip_the_number(number):
    • number = list(number)
    • print(number)
    • num = []
    • for i in range(len(number)):
    • lenth = len(number)
    • num.append(str(number[lenth-1-i]))
    • print(num)
    • join = ""
    • return join.join(num)
    • def flip_the_number(n):
    • # takes int, flips int, return int
    • r = 0
    • while n > 0:
    • r *= 10
    • r += n % 10
    • n //= 10
    • return r