I have this data set that I need to align the columns of ID
, Date
, and Title
. I'm not sure how to align these and how to add a header? I'm not able to use any 3rd party functions like tabulate
. Could someone walk me through on how to do this? I'm a beginner and just need some guidance!
data_set = [['ID=j234hg\n'], ['Date=19 October 1969\n'], ['Title=court scene with cardinal richelieu\n'], ['ID=d45j5jkd\n'], ['Date=28 December 1969\n'], ['Title=THE ROYAL PHILHARMONIC ORCHESTRA GOES TO THE BATHROOM\n'], ['ID=s4k5jk\n'], ['Date=8 December 1970\n'], ['Title=crossing the atlantic on a tricycle\n'], ['ID=zd7u4h\n'], ['Date=19 October 1969\n'], ['Title=Bicycle Repair Man\n'], ['ID=f983\n'], ['Date=22 December 1970\n'], ['Title=Royal Episode 13 (or: The Queen Will Be Watching)\n'], ['ID=j8s74\n'], ['Date=15 September 1970\n'], ['Title=THE SEMAPHORE VERSION OF WUTHERING HEIGHTS\n'], ['ID=n4j6l3j\n'], ['Date=7 December 1972\n'], ['Title=Mr. Pither']]
for index,l in enumerate(data_set):
column_name,value = l[0].split("=")
if 'Title' == column_name:
data_set[index]="=".join([column_name+value.title()])
print (data_set)
rows = [ data_set[i:i+3] for i in range(0,len(data_set), 3)]
print (sum(sorted(rows, key = lambda r:r[0][0]), []))
It needs to look like this:
#ID Date Title
#d45j5jkd 28 December 1969 The Royal Philharmonic Orchestra Goes To The Bathroom
#f983 22 December 1970 Royal Episode 13 (Or: The Queen Will Be Watching)