Months={"01":"January","02":"February","03":"March","04":"April","05":"May","06":"June","07":"July","08":"August","09":"September","10":"October","11":"November","12":"December"}
date_time = lambda D: "{day} {month} {year} year {hour} hour"+"{p1} "+"{minute} minute"+"{p2}".format(day=str(int(D.split('.')[0])),month=Months[D.split('.')[1]],year=D.split('.')[2].split(' ')[0],hour=str(int(D.split(' ')[1].split(':')[0])),p1=''if D.split(' ')[1].split(':')[0]=='01' else 's',minute=str(int(D.split(' ')[1].split(':')[1])),p2=''if D.split(' ')[1].split(':')[1]=='01' else 's')
how it should work :
date_time("01.01.2000 00:00") == "1 January 2000 year 0 hours 0 minutes"
how it does work:
date_time("01.01.2000 00:00") == "{day} {month} {year} year {hour} hour{p1} {minute} minute{p2}"
You're only calling format()
on the last string "{p2"}
because .
has higher precedence than +
. You need to put the concatenations in parentheses.
date_time = lambda D: ("{day} {month} {year} year {hour} hour"+"{p1} "+"{minute} minute"+"{p2}").format(day=str(int(D.split('.')[0])),month=Months[D.split('.')[1]],year=D.split('.')[2].split(' ')[0],hour=str(int(D.split(' ')[1].split(':')[0])),p1=''if D.split(' ')[1].split(':')[0]=='01' else 's',minute=str(int(D.split(' ')[1].split(':')[1])),p2=''if D.split(' ')[1].split(':')[1]=='01' else 's')
Although I don't understand why you're concatenating a bunch of literal strings. Just make it one long string.
date_time = lambda D: "{day} {month} {year} year {hour} hour{p1} {minute} minute{p2}".format(day=str(int(D.split('.')[0])),month=Months[D.split('.')[1]],year=D.split('.')[2].split(' ')[0],hour=str(int(D.split(' ')[1].split(':')[0])),p1=''if D.split(' ')[1].split(':')[0]=='01' else 's',minute=str(int(D.split(' ')[1].split(':')[1])),p2=''if D.split(' ')[1].split(':')[1]=='01' else 's')