Page 200 -
P. 200

hashes and databases


                        Code Magnets

                        Rearrange the code magnets to complete the function required. The following
                        functionality is implemented:
                        1. Accept a single parameter (the surfer ID).
                        2. Process the data file one line at a time, creating a hash from the line on each iteration.
                        3. Compare the parameter against the ID read from the file.
                        4. If the IDs match, return the hash to the caller.
                        5. If no match is found, return an empty hash to the caller.






                   def find_details(id2find):



                       for each_line in surfers_f:











                               surfers_f.close()




                       surfers_f.close()










                                 surfers_f = open("surfing_data.csv")
               return({})                                     s = {}                  return(s)


          (s['id'], s['name'], s['country'], s['average'], s['board'],         if id2find == int(s['id']):
                         s['age']) = each_line.split(";")



                                                                                       you are here 4    165
   195   196   197   198   199   200   201   202   203   204   205