Last active
May 26, 2023 00:21
-
-
Save blluv/f8374bbc3915724b8bb81768174747d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def printAsTable(d: list, index=False): | |
headers = list(d[0].keys()) | |
body = [] | |
for row in d: | |
body.append(list(map(lambda v: row.get(v, ""), headers))) | |
if index: | |
headers = [""] + headers | |
body = list(map(lambda v: [v[0]] + v[1], enumerate(body))) | |
print(tabulate(body, headers, tablefmt="simple_grid")) | |
def printAsTable2(d: list, index=False): | |
headers = list(set(sum(map(lambda v: list(v.keys()), d), []))) | |
body = [] | |
for row in d: | |
body.append(list(map(lambda v: row.get(v, ""), headers))) | |
if index: | |
headers = [""] + headers | |
body = list(map(lambda v: [v[0]] + v[1], enumerate(body))) | |
print(tabulate(body, headers, tablefmt="simple_grid")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment