Search code examples
pythonstringstring-formatting

Format String Vertically


I am receiving such data with python that comes as a string from firebase database. How can I format it into more readable data for the user?

Received Output

{'date': '07-Oct-2019', 'day': 'Monday', 'driver': 'John '}

Desired OutPut

date   : 07-Oct-2019 
day    : Monday
driver : jop

Solution

  • Simple one line should do

    d={'date': '07-Oct-2019', 'day': 'Monday', 'driver': 'John '}
    print("\n".join([k+":"+v for k,v in d.items()]))