# unique_by_key

> **Function** in `langchain_classic`

📖 [View in docs](https://reference.langchain.com/python/langchain-classic/retrievers/ensemble/unique_by_key)

Yield unique elements of an iterable based on a key function.

## Signature

```python
unique_by_key(
    iterable: Iterable[T],
    key: Callable[[T], H],
) -> Iterator[T]
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `iterable` | `Iterable[T]` | Yes | The iterable to filter. |
| `key` | `Callable[[T], H]` | Yes | A function that returns a hashable key for each element. |

---

[View source on GitHub](https://github.com/langchain-ai/langchain/blob/42f8f79293cfb7589e5bc1d74a8ae4dfd0bf15e3/libs/langchain/langchain_classic/retrievers/ensemble.py#L36)