asteriskBài tập Args & Kwargs - Nâng cao

Các bài tập về *args và **kwargs - Nâng cao

  1. Viết decorator @log_calls log tất cả function calls với args và kwargs.

def log_calls(func):
    pass

@log_calls
def add(a, b, c=0):
    return a + b + c

# Test: should log arguments và return value
  1. Viết hàm curry(func, *args) implement currying.

def curry(func, *args):
    # Partial application
    pass

# Test
def add_three(a, b, c):
    return a + b + c

add_5 = curry(add_three, 5)
result = add_5(10, 15)
print(result)  # 30
  1. Viết class FlexibleConfig lưu config với args và kwargs.

  1. Viết hàm pipe(*functions) compose functions.

  1. Viết hàm retry(max_attempts, *exceptions, **options) retry decorator.

  1. Viết DynamicRouter class route requests với dynamic handlers.

  1. Viết hàm memoize_flexible(*args, **kwargs) với custom cache key.

  1. Viết EventEmitter với flexible event handlers.

  1. Viết hàm partial_from_right(*args, **kwargs) partial từ bên phải.

  1. Viết QueryBuilder với chainable methods và flexible conditions.

  1. Viết hàm validate(*validators, **options) decorator validation.

  1. Viết MultiDispatch function overloading với type hints.

  1. Viết hàm batch_process(*items, **config) xử lý batch với retry.

  1. Viết FlexibleCache với LRU và TTL support.

  1. Viết hàm aggregate(*operations, **config) data aggregation.

  1. Viết MiddlewareStack với flexible middleware chain.

  1. Viết hàm transform(*transformers, **config) data transformation pipeline.

  1. Viết AsyncBatch process items async với flexible callbacks.

  1. Viết hàm serialize(*fields, **config) flexible serialization.

  1. Viết StateMachine với flexible transitions và callbacks.

Last updated