title = [ 'Name' , 'Address' , 'Description' ]
input = [ [ 'Reddit' , 'www.reddit.com' , 'the frontpage of the internet' ] , [ 'Wikipedia' , 'en.wikipedia.net' , 'The Free Encyclopedia' ] , [ 'xkcd' , 'xkcd.com' , 'Sudo make me a sandwich.' ] ]
def maxWidth( title, input , i) :
maxwidth = len ( title)
for j in input :
maxwidth = max ( maxwidth, len ( j[ i] ) )
return ( maxwidth + 2 )
def borderString( title, input ) :
string = ""
for i in range ( 0 , len ( title) ) :
width = maxWidth( title[ i] , input , i)
string = string + "+" + ( "-" * width)
string = string + "+"
return string
def titleString( title, input ) :
for i in range ( 0 , len ( title) ) :
width = maxWidth( title[ i] , input , i)
widthleft = ( width - len ( title[ i] ) ) //2
widthright = ( width - len ( title[ i] ) ) //2 + ( width - len ( title[ i] ) ) % 2
print ( "|" , " " * widthleft, title[ i] , " " * widthright, sep= "" , end= "" )
print ( "|" )
def itemString( title, input , i) :
for j in range ( 0 , len ( title) ) :
width = maxWidth( title[ j] , input , j)
widthright = width - len ( input [ i] [ j] ) - 1
print ( "| " , input [ i] [ j] , " " * widthright, sep = "" , end= "" )
print ( "|" )
def main( ) :
string = borderString( title, input )
print ( string )
titleString( title, input )
print ( string )
for i in range ( 0 , len ( input ) ) :
itemString( title, input , i)
print ( string )
main( )
dGl0bGUgPSBbJ05hbWUnLCAnQWRkcmVzcycsICdEZXNjcmlwdGlvbiddCmlucHV0ID0gW1snUmVkZGl0JywgJ3d3dy5yZWRkaXQuY29tJywgJ3RoZSBmcm9udHBhZ2Ugb2YgdGhlIGludGVybmV0J10sWydXaWtpcGVkaWEnLCAnZW4ud2lraXBlZGlhLm5ldCcsICdUaGUgRnJlZSBFbmN5Y2xvcGVkaWEnXSxbJ3hrY2QnLCAneGtjZC5jb20nLCAnU3VkbyBtYWtlIG1lIGEgc2FuZHdpY2guJ11dCgpkZWYgbWF4V2lkdGgodGl0bGUsIGlucHV0LCBpKToKICAgIG1heHdpZHRoID0gbGVuKHRpdGxlKQogIC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