Ad
Code
Diff
  • def even_or_odd(n):  
        return 'EOvdedn'[n & 1:: 2]
    
    • def even_or_odd(n):
    • return "".join(('E','O','v','d','e','d','n')[n&1::2])
    • return 'EOvdedn'[n & 1:: 2]
Code
Diff
  • nums = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
    calc = lambda rom: sum((c := nums[s]) * (1, -1)[i != len(rom) - 1 and nums[rom[i + 1]] > c] for i, s in enumerate(rom))
    compare_roman = lambda a, b : (a := calc(a)) > (b := calc(b)) or -(a < b)
    • nums = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000}
    • calc = lambda num: sum((-1 if e != len(num) - 1 and nums[num[e + 1]] > nums[x] else 1) * nums[x] for e,x in enumerate(num))
    • compare_roman = lambda a, b : calc(a) > calc(b) or -(calc(a) < calc(b))
    • #compare_roman = lambda a, b, calc=lambda num, nums={'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000}: sum((-1 if e != len(num) - 1 and nums[num[e + 1]] > nums[x] else 1) * nums[x] for e,x in enumerate(num)): calc(a) > calc(b) or -(calc(a) < calc(b))
    • #:)
    • nums = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
    • calc = lambda rom: sum((c := nums[s]) * (1, -1)[i != len(rom) - 1 and nums[rom[i + 1]] > c] for i, s in enumerate(rom))
    • compare_roman = lambda a, b : (a := calc(a)) > (b := calc(b)) or -(a < b)
Code
Diff
  • def spawn_to_range(a, v, r): return a[:(i := a.index(v))] + [v] * r + a[i + 1:]
    • def spawn_to_range(a, v, r): i = a.index(v); return a[:i] + [v] * r + a[i + 1:]
    • def spawn_to_range(a, v, r): return a[:(i := a.index(v))] + [v] * r + a[i + 1:]
Code
Diff
  • def even_or_odd(n):  
        return ('Even', 'Odd')[n & 1]
    
    • def even_or_odd(n):
    • return 'Even' if n % 2 == 0 else 'Odd'
    • return ('Even', 'Odd')[n & 1]