Ad
Code
Diff
  • find_max=max
    
    • find_max = lambda x: max(x)
    • find_max=max

Given a 2D list, we want to extract a sublist given the starting point at the top-left (tuple of form (x,y)), and the dimensions of the sublists x (horizontal size) and y (vertical size).

def extract_sublist(l, s, x, y):
    res = []
    for i in range(list(s)[1],y+list(s)[1]):
        res.append(l[i][list(s)[0]:list(s)[0]+x])
    return res
Code
Diff
  • av=abs
    • function av(num) {
    • return Math.abs(num);
    • }
    • av=abs

Bad practice to override exisitng module function.

Code
Diff
  • factorial_=lambda x:reduce(lambda x,y:x*y,range(1,x+1))
    • def factorial(n):
    • if n == 0:
    • return 1
    • else:
    • recurse = factorial(n-1)
    • result = n * recurse
    • return result
    • # thats how i learned it from "think python"
    • factorial_=lambda x:reduce(lambda x,y:x*y,range(1,x+1))
Code
Diff
  • digital_root=lambda n:digital_root(sum(int(i) for i in str(n)))if n>9 else n
    • def digital_root(n):
    • if n>9:
    • return digital_root(sum(int(i) for i in str(n)))
    • return n
    • digital_root=lambda n:digital_root(sum(int(i) for i in str(n)))if n>9 else n
Code
Diff
  • def abbrev(s):
        return s[0] + str(len(s[1:-1])) + s[-1]
    • def abbrev(str):
    • return str[0] + str(len(str[1::-1])) + str[-1]
    • def abbrev(s):
    • return s[0] + str(len(s[1:-1])) + s[-1]
Strings
Data Types
Arrays

Used a lambda function instead.

Input should not be used as a variable/parameter name as it coincides with a method name.

Code
Diff
  • special_fission=lambda s:list(filter(lambda x:x.isalpha(),list(s)))
    • def Special_Fission(input):
    • return list(filter(lambda letter: letter.isalpha(), input))
    • special_fission=lambda s:list(filter(lambda x:x.isalpha(),list(s)))
Code
Diff
  • remove=lambda s:''.join([c for c in s if c.islower()])
    • CAPITAL_LETTERS = ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
    • 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z')
    • NUMBERS = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
    • SPACE = (' ')
    • def remove(ಠ‿ಠ):
    • for category in (CAPITAL_LETTERS, NUMBERS, SPACE):
    • for item in category:
    • while item in ಠ‿ಠ:
    • ಠ‿ಠ = remove(ಠ‿ಠ.replace(item, ''))
    • return ಠ‿ಠ
    • remove=lambda s:''.join([c for c in s if c.islower()])
Fundamentals
Code
Diff
  • e=lambda n:n//2*2
    • e=lambda n:n-(n&1)
    • e=lambda n:n//2*2
Code
Diff
  • package kata
    func Multiple3And5(n int) bool {
        return n%15==0
    }
    • package kata
    • func Multiple3And5(number int) bool {
    • return number%15 == 0
    • func Multiple3And5(n int) bool {
    • return n%15==0
    • }

prod function is added as of 3.8, but it does not work on an empty list.

Code
Diff
  • from math import prod
    def prod_(l):
        return prod(l) if len(l)>0 else 0
    • from functools import reduce
    • from operator import __mul__
    • def prod(numbers):
    • return reduce(__mul__, numbers) if numbers else 0
    • from math import prod
    • def prod_(l):
    • return prod(l) if len(l)>0 else 0
Code
Diff
  • flip_the_number=lambda n:n[::-1]
    • def flip_the_number(num):
    • return num[::-1]
    • flip_the_number=lambda n:n[::-1]

I'm only using true and operands this time

Code
Diff
  • def returnhundred(s):
        return (True + True + True + True + True + True + True + True + True + True) ** (True + True)
        
    • def returnhundred(word):return 100
    • def returnhundred(s):
    • return (True + True + True + True + True + True + True + True + True + True) ** (True + True)
Performance
Puzzles
Games
Fundamentals

Sum a 2D array/list, but try to do both the following:

  • play code golf
  • write performant code - push the amount of huge 1000000 * 1000000 lists multiplied further
f=lambda x:sum(sum(y)for y in x)
Algorithms
Logic
Fundamentals

6 chars saved

Code
Diff
  • validateKey=(k,s=k.split('-'))=>k.length+s[0].length==14&&!isNaN(s[0])&&!isNaN(s[1])&&!'333-444-555-666-777-888-999'.includes(s[0])&&s[1]%7==0&&!'089'.includes(k.slice(-1))
    • const validateKey=(k,s=k.split('-'))=>k.length+s[0].length==14&&!isNaN(s[0])&&!isNaN(s[1])&&!'333-444-555-666-777-888-999'.includes(s[0])&&s[1]%7==0&&!'089'.includes(k.slice(-1))
    • validateKey=(k,s=k.split('-'))=>k.length+s[0].length==14&&!isNaN(s[0])&&!isNaN(s[1])&&!'333-444-555-666-777-888-999'.includes(s[0])&&s[1]%7==0&&!'089'.includes(k.slice(-1))
Loading more items...