Who says that python has always beautiful syntax look at this simple function to print seconds to human readable format and you will see a bad case of python pseudo ternary operator  abuse.

 

def format_duration(seconds):
 if seconds < 1: return 'now'
 m, s = divmod(seconds, 60)
 h, m = divmod(m, 60)
 d, h = divmod(h, 24)
 y, d = divmod(d, 365)
 return ( ('', (str(y) + ' year' , str(y) + ' years' )[y > 1] + ('',(' and', ',')[h > 0])[d > 0 or h > 0 or m > 0 or s > 0 ] )[y>0] +
 ('', (' ' + str(d) + ' day', ' ' + str(d) + ' days')[d > 1] + ('',(' and', ',')[m > 0])[h > 0 or m > 0 or s > 0 ] )[d>0] + 
 ('', (' ' + str(h) + ' hour' , ' ' + str(h) + ' hours')[h > 1] + ('',(' and', ',')[s > 0])[m > 0 or s > 0 ] )[h>0] +
 ('', (' ' + str(m) + ' minute' , ' ' + str(m) + ' minutes')[m > 1] + ('',' and')[s > 0 ] )[m>0] +
 ('', (' ' + str(s) + ' second', ' ' + str(s) + ' seconds')[s > 1] )[s>0] ).strip() 
 

 

Share the joy