For example, there is a dictionary as follows:
>>> dic = {
"Name": "Botoo",
"url": "Http://www.123.com",
"Page": "88",
"Isnonprofit": "true",
"Address": "China",
}
The desired output would be as follows:
First gets the maximum value of the Dictionary max (map (len, Dic.keys ()))
Then use
Str.rjust () Align Right
Or
Str.ljust () Align Left
Or
The Str.center () center method has a sequence of outputs.
>>> dic = { "name":"Botoo", "URL":"http://www.123.com", "page":" the", "Isnonprofit":"true", "Address":" China", }>>> >>> d = max (map (len, Dic.keys ()))#gets the maximum value of the key>>> >>> forKinchDIC:Print(K.ljust (d),":", Dic[k]) Name:botoourl:http:Www.123. Compage:88IsNonProfit:trueaddress:china>>> forKinchDIC:Print(K.rjust (d),":", Dic[k]) Name:botoo url:http:Www.123. com page:88isnonprofit:true Address:china>>> forKinchDIC:Print(K.center (d),":", Dic[k]) Name:botoo url:http:Www.123. com page:88isnonprofit:true Address:china>>>
The use of Str.ljust () also has this;
>>> s ="ADC">>> S.ljust (20,"+")'adc+++++++++++++++++'>>> S.rjust (20)'ADC'>>> S.center (20,"+")'++++++++adc+++++++++'>>>
Python base = = = Aligns the strings to the left and right