python-tabulate
python-tabulate copied to clipboard
Fix headers for list of dicts
This contribution corrects the behavior of the headers option when the input data is a list of dict.
- Fix the behavior of
headers="firstrow". The example below illustrates the current behavior, which is incorrect:
x = [ {'b': 'B', 'a': 'A'},
{'a': 1, 'b': 2},
{'a': 3, 'b': 4, 'c': 5} ]
print(tabulate( x, headers='firstrow' ))
# Current output:
#
# B A c
# --- --- ---
# 2 1
# 4 3 5
# Proposed output:
#
# B A
# --- ---
# 2 1
# 4 3
- Fix the current behavior when
headersis specified as a list of keys:
x = [ {'a': 1, 'b': 2},
{'a': 3, 'b': 4, 'c': 5} ]
print(tabulate( x, headers=['b','a'] ))
# Current output:
#
# b a
# -- --- ---
# 1 2
# 3 4 5
# Proposed output:
#
# b a
# --- ---
# 2 1
# 4 3