1. 程式人生 > >Python - 將字典內容印成一個格式化報告

Python - 將字典內容印成一個格式化報告

def report(wages):
    students = list(wages.keys())
    students.sort()
    for student in students:
        print("%-20s %12.2f" % (student, wages[student]))


if __name__ == '__main__':
    wages = {'mary': 6.23, 'joe': 5.45, 'joshua': 4.25}
    report(wages)



#joe                          5.45
#joshua                       4.25
#mary                         6.23