Skip to content

Instantly share code, notes, and snippets.

@V0XNIHILI
Last active July 19, 2022 10:38
Show Gist options
  • Save V0XNIHILI/8a0050da43f03f84635c19688c2fdb22 to your computer and use it in GitHub Desktop.
Save V0XNIHILI/8a0050da43f03f84635c19688c2fdb22 to your computer and use it in GitHub Desktop.
Python implementation of Haskell's zipWith
from typing import List, Any, Callable
def zip_with (func: Callable[[Any, Any], Any], list1: List[Any], list2: List[Any]) -> Any:
"""
>>> zip_with (lambda x, y: x + y, [1, 2, 3], [4, 5, 6])
[5, 7, 9]
"""
return [func (x, y) for x, y in zip (list1, list2)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment