Repository: Textualize/textual
File: src/textual/widgets/_key_panel.py (Python)

Code before:
                title.stylize(header_style)
                table.add_row("", title)

            action_to_bindings: defaultdict[str, list[tuple[Binding, bool, str]]]
            action_to_bindings = defaultdict(list)
            for _, binding, enabled, tooltip in table_bindings:
                action_to_bindings[binding.action].append((binding, enabled, tooltip))

            description_style = self.get_component_rich_style(
                "bindings-table--description"
            )

            def render_description(binding: Binding) -> Text:
                """Render description text from a binding."""
                text = Text.from_markup(
                    binding.description, end="", style=description_style
                )
                if binding.tooltip:
                    text.append(" ")
                    text.append(binding.tooltip, "dim")
                return text

            get_key_display = self.app.get_key_display
            for multi_bindings in action_to_bindings.values():
                binding, enabled, tooltip = multi_bindings[0]
                unique_key_displays: list[str] = []
                for binding, _, _ in multi_bindings:
                    key_display = get_key_display(binding)
                    if key_display not in unique_key_displays:
                        unique_key_displays.append(key_display)
                keys_display = " ".join(unique_key_displays)
                table.add_row(
                    Text(keys_display, style=key_style),
                    render_description(binding),
                )
            if namespace != previous_namespace:
                table.add_section()

            previous_namespace = namespace

        return table

    def render(self) -> Table:
        return self.render_bindings_table()


class KeyPanel(VerticalScroll, can_focus=False):
    """
    Shows bindings for currently focused widget.
    """


Review comment (suggestion):
I'd be tempted to go with this. Faster, but uses an idiom not everyone is familiar with.

```python
keys_display = " ".join(
    dict.fromkeys(
        get_key_display(binding) for binding, _, _ in multi_bindings
    )
)
```

Code after:
                title.stylize(header_style)
                table.add_row("", title)

            action_to_bindings: defaultdict[str, list[tuple[Binding, bool, str]]]
            action_to_bindings = defaultdict(list)
            for _, binding, enabled, tooltip in table_bindings:
                action_to_bindings[binding.action].append((binding, enabled, tooltip))

            description_style = self.get_component_rich_style(
                "bindings-table--description"
            )

            def render_description(binding: Binding) -> Text:
                """Render description text from a binding."""
                text = Text.from_markup(
                    binding.description, end="", style=description_style
                )
                if binding.tooltip:
                    text.append(" ")
                    text.append(binding.tooltip, "dim")
                return text

            get_key_display = self.app.get_key_display
            for multi_bindings in action_to_bindings.values():
                binding, enabled, tooltip = multi_bindings[0]
                keys_display = " ".join(
                    dict.fromkeys(  # Remove duplicates while preserving order
                        get_key_display(binding) for binding, _, _ in multi_bindings
                    )
                )
                table.add_row(
                    Text(keys_display, style=key_style),
                    render_description(binding),
                )
            if namespace != previous_namespace:
                table.add_section()

            previous_namespace = namespace

        return table

    def render(self) -> Table:
        return self.render_bindings_table()


class KeyPanel(VerticalScroll, can_focus=False):
    """
    Shows bindings for currently focused widget.
    """

    DEFAULT_CSS = """