# 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/f0c5a28fa05adcda89aebcb449d897245ab21fa4/libs/langchain/langchain_classic/retrievers/ensemble.py#L36)