Skip to content

Instantly share code, notes, and snippets.

@vlad-bezden
Last active November 2, 2018 12:31
Show Gist options
  • Save vlad-bezden/7ca08e3dd0bb19a3eac099eca797cd53 to your computer and use it in GitHub Desktop.
Save vlad-bezden/7ca08e3dd0bb19a3eac099eca797cd53 to your computer and use it in GitHub Desktop.
Python doesn't have 'first' function. Here is an example of implementation of it.
from typing import Callable, Iterable, Any
def first(predicate: Callable, collection: Iterable) -> Any:
for x in collection:
if predicate(x):
return x
def first(predicate: Callable, collection: Iterable) -> Any:
return next((x for x in collection if predicate(x)), None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment