Converting Python 3.6.5 List to a table

前端 未结 3 1489
滥情空心
滥情空心 2021-01-28 14:25

I am currently working on a project and I need help on converting a list to a table. I have figured it out one way but there has to be a shorter and a cleaner way of doing it an

3条回答
  •  闹比i
    闹比i (楼主)
    2021-01-28 14:26

    Try to use one of many popular packages available to print tabular o/p. My suggestion is to use tabulate

    from tabulate import tabulate
    sales_persons_list = list('ABCDE')
    sales_amounts_list = list('12345')
    print (tabulate(zip(sales_persons_list, sales_amounts_list), tablefmt="plain"))
    

    Output

    A  1
    B  2
    C  3
    D  4
    E  5
    

提交回复
热议问题