Skip to content

Instantly share code, notes, and snippets.

@omas-public
Last active July 6, 2026 00:44
Show Gist options
  • Select an option

  • Save omas-public/09b5d6d8657fd6831e9c516ed6ada6be to your computer and use it in GitHub Desktop.

Select an option

Save omas-public/09b5d6d8657fd6831e9c516ed6ada6be to your computer and use it in GitHub Desktop.
0629.md

0629

from functools import reduce
def fun(M, *args):
    rfun = lambda x, y: x + y
    return reduce(rfun, args) <= M
    # or return sum(args) <= M
def fun(mx):
    sfun = lambda x: int(x[0])
    return list(dict(sorted(mx, key = sfun)).values())
def fun(M, *args):
    ffun = lambda M: lambda n: n <= M
    return filter(ffun(M), args)  
def fun(M, *args):
    index = M % (len(args) - 1)
    return args[index]
from functools import cmp_to_key
def fun(*args):
    sfun = lambda a, b: 1 if a + b >= b + a else -1
    return sorted(args, key = cmp_to_key(sfun))
def isLeap(year):    
    can_div = lambda base: lambda n: base % n == 0
    count = sum(map(can_div(year), (4, 100, 400)))
    return not can_div(count)(2)
    
# or
# from calendar import isLeap
# def fun(year):
#     return isLeap(year)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment