Ad
Mathematics
Logic

statistics

Code
Diff
  • average = lambda x: [__import__("statistics").mean(i) for i in zip(*x)]
    • def average(t: tuple[tuple[int | float, ...], ...]) -> list[int | float]:
    • return [sum(i) / len(i) for i in zip(*t)]
    • average = lambda x: [__import__("statistics").mean(i) for i in zip(*x)]

jsfuck

Code
Diff
  • var a = 1;
    • var a = 1;
    • //Change the Variable 'a' to 10;
    • var a = 1;

different slice

Code
Diff
  • binary=lambda n:bin(n)[-7:]
    
    • binary = lambda n: bin(n)[2:]
    • binary=lambda n:bin(n)[-7:]

short

Code
Diff
  • ret_1=lambda:ord('d')/100
    • ret_1=lambda x:100-99
    • ret_1=lambda:ord('d')/100
Fundamentals

might not be right, idk

Code
Diff
  • class Solution:
        def __init__(self, n, lst1, lst2):
            self.n = n
            self.lst1 = lst1
            self.lst2 = lst2
            
        def xor_list(self):
            return not ((self.n in self.lst1 and self.n in self.lst2)) if (self.lst1.count(self.n) != 0 or self.lst2.count(self.n) != 0) else False 
        
        
    • class Solution:
    • def __init__(self, n, lst1, lst2):
    • self.n = n
    • self.lst1 = lst1
    • self.lst2 = lst2
    • def xor_list(self):
    • return self.n in self.lst1 and self.n not in self.lst2 or self.n in self.lst2 and self.n not in self.lst1
    • return not ((self.n in self.lst1 and self.n in self.lst2)) if (self.lst1.count(self.n) != 0 or self.lst2.count(self.n) != 0) else False
Fundamentals

changed to one method, made it short

Code
Diff
  • def replace_key(d, k1, k2):d[k2]=d.pop(k1);return d
    • class Solution:
    • def __init__(self , d:dict):
    • self.d = d
    • def rename_dict_key(self, old, new):
    • self.d[new] = self.d.pop(old)
    • return self.d
    • def replace_key(d, k1, k2):d[k2]=d.pop(k1);return d

exec time

Code
Diff
  • exec("".join([chr(i)for i in[101,118,101,110,95,111,114,95,111,100,100,61,108,97,109,98,100,97,32,95,58,39,69,118,101,110,39,105,102,32,95,95,105,109,112,111,114,116,95,95,40,34,109,97,116,104,34,41,46,114,101,109,97,105,110,100,101,114,40,95,44,50,41,61,61,48,32,101,108,115,101,39,79,100,100,39]]))
    • q9igropqwepoifqpowiepowqihgpoqiwheiophPOIOIHPOIWHOPIEHOPIEFHPOIpiurepiuhfafoiuh3awiuoiueaheiouhwoiu=lambda _:"".join(chr(_) for _ in (69, 118, 101, 110)) if __import__("".join(chr(_) for _ in (109, 97, 116, 104))).remainder(_,True+True)==False else "".join(chr(_) for _ in (79, 100, 100))
    • even_or_odd=q9igropqwepoifqpowiepowqihgpoqiwheiophPOIOIHPOIWHOPIEHOPIEFHPOIpiurepiuhfafoiuh3awiuoiueaheiouhwoiu
    • exec("".join([chr(i)for i in[101,118,101,110,95,111,114,95,111,100,100,61,108,97,109,98,100,97,32,95,58,39,69,118,101,110,39,105,102,32,95,95,105,109,112,111,114,116,95,95,40,34,109,97,116,104,34,41,46,114,101,109,97,105,110,100,101,114,40,95,44,50,41,61,61,48,32,101,108,115,101,39,79,100,100,39]]))

Added math

Code
Diff
  • even_or_odd=lambda _:'Even'if __import__("math").remainder(_,2)==0 else'Odd'
    • even_or_odd=lambda _:'Odd'if _&1else'Even'
    • even_or_odd=lambda _:'Even'if __import__("math").remainder(_,2)==0 else'Odd'

Return the remainder of x divided by y. If either x or y is 0, return -1.

def remainder(x, y):
    if x == 0 or y == 0:
        return -1
    rem = x % y
    return rem
Performance

Fixed up the tests a little bit, switched to threading :D

Code
Diff
  • from threading import Thread
    
    @spindle_speed
    def needle_and_thread():
        for i in range(7):
            Thread(target=sewing_needle).start()
    
    • import concurrent.futures
    • from threading import Thread
    • @spindle_speed
    • def needle_and_thread():
    • with concurrent.futures.ThreadPoolExecutor() as spool:
    • for thread in range(7):
    • spool.submit(sewing_needle)
    • for i in range(7):
    • Thread(target=sewing_needle).start()

silly ord

Code
Diff
  • ret_1=lambda x:ord("\x01")
    • exec(bytes('桳畯摬牟瑥牵彮㴱慬扭慤渠⠺‭⥮ㄫ', 'u16')[2:])
    • """
    • ....................................................................................................
    • .........:;;:..........::::::::,......,:::::,,............,::,..........,::::,,.........::,....::,..
    • .......,%@@@@S:.......,@@@@@@@@+......:@@@@@@@%,..........+@@*..........%@@@@@#?,.......S@+...,@@;..
    • .......%@@%%@@#,......,@@#SSSSS;......:@@SSSS@@%..........S@@#,.........S@#SS#@@*.......#@*...,@@;..
    • ......,@@;..;@@;......,@@;............:@@:...*@@,........:@@@@;.........S@?..,%@#,......#@+...,@@;..
    • ......,@@*,..;;,......,@@:............:@@,...;@@:........?@%?@%.........S@?...+@#,......#@+...,@@;..
    • .......?@@@S*:........,@@S%%%%%,......:@@*++*#@S........,#@;;@@:........S@?,,:S@S.......#@#%%%S@@;..
    • .......,?#@@@@?,......,@@@@@@@#,......:@@@@@@@S:........+@#..#@*........S@@@@@@@;.......#@@@@@@@@;..
    • .........,;?S@@+......,@@+:::::.......:@@??@@%,.........S@%;;%@#,.......S@@###%;........#@?:::;@@;..
    • ......:?*....%@%......,@@:............:@@,.;@@?........:@@@@@@@@;.......S@?,,...........#@+...,@@;..
    • ......;@@;...%@%......,@@:............:@@:..*@@+.......?@#????#@%.......S@?.............#@+...,@@;..
    • ......,S@@%?S@@+......,@@S%%%%%+......:@@:..,S@#,.....,#@*....+@@:......S@?.............#@+...,@@;..
    • .......:S@@@@@*.......,@@@@@@@@?......:@@:...:@@?.....+@@,....,#@*......S@?.............#@*...,@@;..
    • .........;++;,........,;;;;;;;;:......,;;,....:;:.....:;:..,:..:;:......:;:.............:;,...,;;,..
    • ..........................................................;*%?......................................
    • .........................................................,;+S#;.....................................
    • .........................................................;*S@S*,....................................
    • .........................................................:*S#S*,....................................
    • .........................................................,*#S@*,....................................
    • .........................................................,+@#@?:....................................
    • .........................................................,;%%?*,....................................
    • ..........................................................+***;,....,:..............................
    • ..........................................................:?S%+......:,.............................
    • ..........................................................,*S%+......::.............................
    • ..........................................................,*%?;......,;.............................
    • ...........................................................*%%+......:;.............................
    • ...........................................................*SS*......;;.............................
    • ..........................................................,*SS*.....:*,.............................
    • ..........................................................,?%S?,...:*;..............................
    • ..........................................................,*SSS+:;*?;...............................
    • .......................................................,:;.+%?%??*;,................................
    • ......................................................:+*?.;%?*,,...................................
    • ....................................................,++**;.;S%+,....................................
    • ...............................,,:::::,,...........,+*?+,,.+S%:.....................................
    • ............................,:;+**++;;+++:........,+*%;..,,*S?,.....................................
    • ..........................::+++%%%*+;;;;;**:......+*%;...,;?%*,.....................................
    • ........................,+?**%S#@@#??*+;;;;**:...;*%+....;???+......................................
    • ........................?S*%##@@@@@S%%%%?+;;+%?:,???....+S?*?:......................................
    • .......................;#%SS@@@@S%*+::;*%S?+:+?%?%%:..,*S?+**,......................................
    • ......................,%##%S@@#?+;;:::::;*%S?;;*?%%+;+%%*;+*:.......................................
    • ......................+##S*S@#?+:,,.,,:;;;;?S%+;+**?%%*+;;*+........................................
    • .....................,%##%;%#%+:........:*+;+****+***++;+*+,........................................
    • .....................:S##?:*SS;...........:+;:;++********;..........................................
    • .....................;S##*:*S%;.............::;;:;;++++:,...........................................
    • .....................+###*:+SSS???*+:,.......,:;++;:,,,.............................................
    • .....................+###?:+%#S?**?%%%*:.......:*?;:,,,::;:,........................................
    • .....................;S@@%;+%#S+::::;*?%?:.....;?*;.;*SS###%*:......................................
    • .....................?#@@#++*#S?+;;:,,:;?%+,...:?;*%##SS%%S@@#?:....................................
    • ....................?##@@@%;+%S%?**++;:,:+??:...??##S?+;;+%@@@@S;,..................................
    • ...................*S?##@@%*;+SS%??**++;:,:*%;.,%##%+:;?%%S#@@@@#+,.................................
    • ..................:#%*S@@#+%;:*SSS%%??*++;:,+%+?#S?;;?SSS#%??%#@@S;.................................
    • ..................?#?+%#@S++%;:*SSS#S%??*++:,;S##?;*SSS??+:.,:+S@@?,................................
    • .................,SS?;?#@S;;**;:%%:;%#S%?*++;;S#S?%###%+:,.,,..+#@S:................................
    • .................:#S?:+S##++*%+;+S*..:%#%?*++%##S#@@#?;:;+,;:,.,*#S;................................
    • .................;@S?;:*S#S;;?*;:?S:...*#S?**####@@#?:,,;*+:....:%S+,...............................
    • .................:##%+:;?#S*+S%+;;S?....+#S?%S@@@@S*;.:?%%S?*;..,*S+,...............................
    • .................,S#S?;:+S#%;+S*;:%S,....+#S??S#@#*;;:,S%%?***+,:+?;,...............................
    • ..................?#S%*;;*S#S;%?;:?#+.....;S++#@@?;+SS::%S?***+*+;+;,...............................
    • ..................;#S%%*;+?#@+?%;:*@?......,:+S@#+;%SS%,.;%%**+*%*%*,...............................
    • ..................:%#SS%?+*S@?*%;;?@S,.....,:*#@S;;#%?S*..,?%*++?%*;,...............................
    • ...................+##SS%%?%#?+%+*?%#,.....,:*@@%:*#%??S:..,%?+;+S*,................................
    • ...................,?####SSS#++%%@#*S:.....,:?@@?:?#%?*%*,::*?+:;S+,................................
    • ....................:?#@@###?:+%#@#+?:.....:;%@@*;%#%?*?#S##%?;,+S?,................................
    • .....................,+%??SS;:;%@@#;?+,....+*%@#*+##%%*?S@#S%*:,*#+.................................
    • .......................:;::::::S@@S;%?*+;;;%?S@#+?##%%**%##%?+,:%#+.................................
    • ............................,::+@@S+%**??%S#?#@S;*SSS%?*??%?+::*S#:.................................
    • ............................,:;+S@#*%+;+++*%?@@%+@*+#%%????*;;?%#?,.................................
    • .............................,:;%@@?S?*+++*?S@@*;+;:S#%%???*?%%SS:..................................
    • .............................,;:*@@%%#%%??%%@@S+::;.;##S%%%%SS#S:...................................
    • ..............................::;#@S%##SSS%S@@?;::;,.:%#######*:....................................
    • ..............................,::?@#*S###S?#@#+::;:,..,;*%%%?:,.....................................
    • ..............................,::+#%S%S#%*S#S*:::;,.......,.........................................
    • ...............................,::?%??%%%S##*:::::..................................................
    • ................................,;;S*+++*?%*;:;::,..................................................
    • .................................:*S%?**?%%;::::,...................................................
    • .................................,;?SS%%S%*;;::,....................................................
    • ..................................,;?###S?;::,......................................................
    • ....................................,;+*+:,,........................................................
    • ....................................................................................................
    • ....................................................................................................
    • .....+#;..........,?#S;..........,?#S;............;#+...........,S?...........+SS*...........+SS*,..
    • ....;@@+..........%@#@@:.........%@#@@:..........:#@+..........,%@%..........+@@@@*.........+@@#@*..
    • ..,?@@@;.........:@S,+@?........:@S,+@?.........*@@@+.........;#@@%..........S@:,@#,........S@;,@@,.
    • ..,@%%@;.........+@?.:@S........+@?.:@S........,@S?@+.........%#*@%.........,@#..S@:.......,@#,.S@:.
    • ..,;.?@;.........*@*.,@#........*@*.,@#,.......,;.*@+.........;,:@%.........:@#..%@;.......,@#..%@;.
    • .....?@;.........*@*.,@#........*@*.,@#,..........*@+...........:@%.........:@#..%@;.......:@#..%@;.
    • .....?@;.........*@*.:@S........+@?.:@#...........*@+...........:@%.........,@#..S@:.......,@#,.%@;.
    • .....?@;.........;@%.;@%........;@%.;@%...........*@+...........:@%.........,#@,.#@,.......,#@,.#@,.
    • .....?@+.........,#@?S@+........,#@?S@+...........*@+...........:@%..........?@%?@%.........?@%?@%..
    • .....*@;..........;#@@?..........;#@@?............*@+...........:@%..........,%@@S:.........,%@@S:..
    • .....,,,...........,::............,::.............,,,............,,............::,............::,...
    • ....................................................................................................
    • """
    • ret_1=lambda x:ord("\x01")

Even smaller

Code
Diff
  • even_or_odd=lambda n:'Even'if n%2is 0else'Odd'
    • even_or_odd = lambda n:'Even' if n & 1 == 0 else 'Odd'
    • even_or_odd=lambda n:'Even'if n%2is 0else'Odd'

smol

Code
Diff
  • pennies = lambda x: x*100
    • def pennies(dollar):
    • ffffffffff = 100*dollar
    • return ffffffffff
    • pennies = lambda x: x*100

Smol

Code
Diff
  • solution = lambda: 10
    • def solution():
    • x = 33212112321312312 - 33212112321312302 * 1
    • return x
    • solution = lambda: 10

One line shorter!

Code
Diff
  • from string import punctuation
    
    
    class Solution:
        def __init__(self, line):
            self.line = line
    
        def max_length_word(self):
            l = self.line.split(", ")
            for i in range(len(l))[::-1]:
                for j in l[i]:
                    if j in punctuation:
                        del l[i]
                        break
            return l[[len(i) for i in l].index(max([len(i) for i in l]))]
    • from string import punctuation
    • class Solution:
    • def __init__(self, line):
    • self.line = line
    • def max_length_word(self):
    • l = self.line.split(", ")
    • for i in range(len(l))[::-1]:
    • for j in l[i]:
    • if j in punctuation:
    • del l[i]
    • break
    • lens = [len(i) for i in l]
    • return l[lens.index(max(lens))]
    • return l[[len(i) for i in l].index(max([len(i) for i in l]))]
Loading more items...