<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">hello! <div><br></div><div>I am doing my homework now and I am kinda stuck. Could any of you help me out? </div><div><br></div><div><div><br></div><div>Here is the homework problem:</div><div><span class="Apple-style-span" style="font-family: monospace; white-space: pre-wrap; "><br></span></div><div><span class="Apple-style-span" style="font-family: monospace; white-space: pre-wrap; "> fieldict(filename) reads a file in DOT format and </span></div><div><pre style="color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; word-wrap: break-word; white-space: pre-wrap; ">      returns a dictionary with the DOT CMPLID, converted to an
      integer, as the key, and a tuple as the corresponding value
      for that key.  The format of the tuple is:
         (manufacturer, date, crash, city, state)
      where these tuple items have the following types:
         manufacturer -- this comes from the MFR_NAME field in the DOT format 
         date -- this comes from the FAILDATE field in the DOT format, 
                 but converted to a Python datetime.date object
         crash -- this comes from the CRASH field in the DOT format, 
                 but converted to a Python bool type (True for a crash)
         city -- comes from the CITY field in the DOT format
         state -- comes from the STATE field in the DOT format
</pre></div><div>should return: <span class="Apple-style-span" style="font-family: monospace; white-space: pre-wrap; ">fieldict("DOT500.txt")[82]</span></div><pre style="color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; word-wrap: break-word; white-space: pre-wrap; ">  ('FORD MOTOR COMPANY', datetime.date(1995, 1, 1), False, 'MARBLE HEAD', 'MA')
</pre><div><br></div><div><br></div><div>and here are parts of the data:</div><div><br></div><div><pre style="color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; word-wrap: break-word; white-space: pre-wrap; ">1     958164  TOYOTA MOTOR CORPORATION        TOYOTA  LAND CRUISER    1994            19941223        N       0       0       SERVICE BRAKES, HYDRAULIC:ANTILOCK      ARNOLD          CA      JT3DJ81W8R0     19950103        19950103                        ABS SYSTEM FAILURE, AT 20MPH.  TT       EVOQ                                                                                                                                                                                                    V       
2       958156  TOYOTA MOTOR CORPORATION        TOYOTA  PASEO   1994    Y       19941226        N       0       0       PARKING BRAKE:CONVENTIONAL      SAN JOSE        CA      JT2EL45U5R0     19950103        19950103                1       PARKED ON FLAT SURFACE EMERGENCY BRAKING ENGAGED VEHICLE ROLLED REARWARD.  TT   EVOQ                                                                                                                                                                                                    V       
3       958124  TOYOTA MOTOR CORPORATION        TOYOTA  COROLLA 1994    Y       19941128        N       0       0       AIR BAGS:FRONTAL        PHOENIX         AZ              19950103        19950103                        UPON FRONTAL COLLISION, AIR BAG FAILED TO DEPLOY. VEHICLE CLASSIFIED AS TOTALED. PLEASE DESCRIBE DETAILS.  TT   EVOQ                                                                                                                                                                                                    V       
4       958122  NISSAN NORTH AMERICA, INC.      NISSAN  MAXIMA  1994            19950103        N       0       0       SUSPENSION      TUCSON          AZ      JN1HJ01F4RT     19950103        19950103                        THE STRUT WAS BAD THERE IS A NOISE ON THE PASSENGER SIDE DOOR AND THE ENGINE LIGHT MALFUNCTION.  TT     EVOQ                                                                                                                                                                                                    V       
5       958122  NISSAN NORTH AMERICA, INC.      NISSAN  MAXIMA  1994            19950103        N       0       0       ENGINE AND ENGINE COOLING:ENGINE        TUCSON          AZ      JN1HJ01F4RT     19950103        19950103                        THE STRUT WAS BAD THERE IS A NOISE ON THE PASSENGER SIDE DOOR AND THE ENGINE LIGHT MALFUNCTION.  TT     EVOQ                                                                                                                                                                                                    V       </pre><div><br></div></div><div><br></div><div><br></div><div>Here is my code and I dont know why my code is only reading the 500th line of the file. Thanks for your help! </div><div><br></div><div><br></div><div>import datetime</div><div>def boolean(S):</div><div>  if S=="Y":</div><div>    return True</div><div>  return False</div><div><br></div><div>def fieldict(filename):</div><div>  D={}</div><div>  with open(filename) as FileObject:</div><div>    for lines in FileObject:</div><div>      linelist=lines.split('\t')</div><div>      Key=linelist[0]</div><div>      ValCity=(linelist[12]).strip()</div><div>      ValState=linelist[13]</div><div>      ValOne=linelist[2]</div><div>      ValTwo=linelist[6]</div><div>      ValThree=boolean(linelist[7])</div><div>  D={Key:(ValOne, ValTwo, ValThree, ValCity,ValState)}</div><div>  return D</div><div>print fieldict("DOT500.txt")</div><div>            </div></div></body></html>