From 9a4c3bd44c3578db14e199fdc122bb413dff0bcc Mon Sep 17 00:00:00 2001 From: Bridget Date: Sun, 19 Apr 2020 22:34:53 +0200 Subject: [PATCH] Pretty-print dict with one list --- lslsh.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lslsh.py b/lslsh.py index 8691472..56ae540 100755 --- a/lslsh.py +++ b/lslsh.py @@ -61,6 +61,13 @@ class Shell(cmd.Cmd): data[0][i] = f"\033[4m{Style.BRIGHT}{item}{Style.NORMAL}\033[0m" return tabulate(data, headers="firstrow", tablefmt="plain") + elif isinstance(data, dict) and len(data.values()) == 1: + # Dict with one list; return a single column with header + header: str = next(iter(data.keys())) + values: list = next(iter(data.values())) + result = [f"\033[4m{Style.BRIGHT}{header}{Style.NORMAL}\033[0m"] + result.extend(values) + return "\n".join(result) except TypeError: pass