I learn what I can and cannot do with the method format().
format()
Let's say I'm trying to format the string "5/11/2013"as "11 May 2013".
"5/11/2013"
"11 May 2013"
Here is what I tried:
string = "5/11/2013" dictionary = {"5": "May"} print "{part[1]} {month[{part[0]}]} {part[2]}".format( part=string.split('/'), month=dictionary)
What returns:
KeyError: '{part[0'
What am I doing wrong? Is it even possible to enclose arguments such as {month[{part[0]}]}?
{month[{part[0]}]}
possibly in two stages:
>>> dictionary = {5: "May"} >>> "{part[1]} {{month[{part[0]}]}} {part[2]}".format(part=string.split('/')).format(month=dictionary) '11 May 2013'
Why not try it like this:
string = "5/11/2013".split('/') dictionary = {"5": "May"} print "{} {} {}".format(string[1],dictionary[string[0]],string[2])
It is also easier to understand than what you do there.
Source: https://habr.com/ru/post/1534032/More articles:C ++ error when using struct variable - c ++How to change indicators and controls of bootstrap carousel - htmlHow to write a reactive web application with Django? - djangowhy the toMillis () function returns -1 in java - java7 "contact date field not working properly - jquery-ui-datepickerTree using ul li and javascript without plugin - javascriptPhonegap Sound stops playing after calling playAudio () 30 to 40 times - androidТестирование частных переменных - всегда плохая практика? - javaDjango CMS - Заполнитель для режима редактирования - pythonClojure требуется пространство имен: "Не знаю, как создать ISeq из: clojure.lang.Keyword" - clojureAll Articles