Question: Im having issues with this python code, the main goal for this program is for it to read a file creating a list where it

Im having issues with this python code,

the main goal for this program is for it to read a file creating a list where it checks to see if the first item on each line is either an I or R. if its an I it will store a the date plus the event on that date as a dictionary, and if the first item of the line is an R it will print out the date and all the events that are related to that date. The dates in the file are shown to be in difrent formats but to have the same date, we are told change the format to year, month, day. This is what i have so far on my code.

 Im having issues with this python code, the main goal for

This is an example output:

this program is for it to read a file creating a list

and this is the file that im using to test it.

I 1960-02-27 : U.S. Olympic hockey team beats Soviet Union I 1897-2-27 : Britain recognizes U.S. authority over Western Hemisphere I Apr 5 1974 : World Trade Center, then the world's tallest building, opens in New York I 1946-1-10: UN General Assembly meets for 1st time (London) R Feb 27 1960 I 3/4/1861 : Abraham Lincoln is inaugurated as 16th US President I 4/5/1242: Alexander Nevsky of Novgorod defeats Teutonic Knights in the Battle of the Ice I Apr 5 1879 : Chile declares war on Bolivia and Peru, starting the War of the Pacific R 1879-04-05 I 6/25/1667 : First blood transfusion performed by French Doctor Jean-Baptiste Denys I 1876-06-25 : Battle of the Little Bighorn R 6/25/1876 I Jul 20 1881 : Sioux Indian Chief Sitting Bull, surrenders to US federal troops I Jul 20 1921: Congresswoman Alice Mary Robertson becomes the first woman to preside over the US House of Representatives I 1954-07-20: Armistice for Indo-China signed, Vietnam separates into North & South I 1969-7-20: 1st Moon Landing: Neil Armstrong and Buzz Aldrin from Apollo 11 R 7/20/1921 R 07/20/1969 R Jul 20 1954

def read_file): file-open( ' date-short . txt') #file- input( ) #f- open(file) date-str=[] for words in file: #creates the list of words of the file date_str.append(words. splitO) return date str FT This function reads the string and checks how the date is being written. It would then split the list based if it has a '-', '/' and ' '. Then sets the valables based on what is the index of the list def canonicalize date(date str): #if the sring was given as yyyy-mm-dd if'-in date_str: d-date_str.split(-" yyyy - dL0] dd - d[2] mm-d1] #if the string was given as mm/dd/yyyy elif'/' in date-str : d - date str.split/ mm-d[0] dd = d[1] #if the string was given as: Monthname dd #made a dict and set the keys as the months and values as the index of the string else: d-date_str.split('") d_index-dL0] month= { 'Jan ' : 1 , 'Feb ' :2, "Ma r ' :3, 'Ap r ' :4, 'May ' :5, 'Jun ' :6, 'Jul ' :7, 'Aug ' :8, 'Sep ' :9, 'Oct ' : 10, 'Nov ' : 11, 'Dec':12} yyyyd 2] mmmonth[d_index] scheme":d-t:dj-:d".format(int(yyyy), int(mm), int(dd)) print(scheme) return scheme def mainO date_str-read_fileO schemecanonicalize_date(date_str) mainC)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!