print a list of dictionaries in table form
python
Solution
How about this:
from __future__ import print_function
dataset =[{'Major': 'Biology', 'GPA': '2.4', 'Name': 'Edward'},Physics', 'GPA': '2.9', 'Name': 'Emily'},Mathematics', 'GPA': '3.5', 'Name': 'Sarah'}]
[print("%s %s: %s\n"%(item['Name'],item['Major'],item['GPA'])) for item in dataset]
result:
Edward Biology: 2.4
Emily Physics: 2.9
Sarah Mathematics: 3.5
Problem
assume I have this list as global list ``` dataset =[{'Major': 'Biology', 'GPA': '2.4', 'Name': 'Edward'}, {'Major': 'Physics', 'GPA': '2.9', 'Name':'Emily'}, {'Major':'Mathematics', 'GPA': '3.5', 'Name': 'Sarah'}] ``` and a want a function print() to print it as ``` name major GPA =============================== edward Biology 2.4 Emily physics 2.9 sarah mathematics 3.5 ```