Please answer it in Python Below are the first 4 lines of such a file whose number of lines is not known a priori: Bella 91.0 18.5 19.5 19.5 19.0 19.5 (91 is a dist note) Azhar 83.0 19.0 18.5 18.5 18.5 19.0 Clara 91.0 17.5 17.5 17.5 18.5 19.0 Dalton 92.5 17.0 18.5 18.5 17.5 18.0 Write a function import_result that takes as an argument the name of the file that contains the results file_name and reads it to make the list of results. Each item in this result list is a dictionary corresponding to a competitor. The keys to this dictionary are: • 'name' with the competitor's name associated • 'note_dist' with which is associated the score obtained by the competitor for the length of his jump. It is known from the question. • 'notes_style' to which is associated the list of 5 marks obtained by the competitor for the style of his jump. Thus, if the file passed as an argument consists only of the 4 lines given as an example previously, the function will return: [{'name': 'Bella', 'notes_style': [18.5, 19.5, 19.5, 19.0, 19.5], 'note_dist': 91.0}, {’nom’: Azhar, ’notes_style’: [19.0, 18.5, 18.5, 18.5, 19.0], ’note_dist’: 83.0}, {'name': Clara, 'notes_style': [17.5, 17.5, 17.5, 18.5, 19.0], 'note_dist': 91.0}, {'name': 'Dalton', 'notes_style': [17.0, 18.5, 18.5, 17.5, 18.0], 'note_dist': 92.5}] Warning: we remind you that by
Please answer it in Python
Below are the first 4 lines of such a file whose number of lines is not known a priori:
Bella 91.0 18.5 19.5 19.5 19.0 19.5 (91 is a dist note)
Azhar 83.0 19.0 18.5 18.5 18.5 19.0
Clara 91.0 17.5 17.5 17.5 18.5 19.0
Dalton 92.5 17.0 18.5 18.5 17.5 18.0
Write a function import_result that takes as an argument the name of the file that contains the results file_name and reads it to make the list of results. Each item in this result list is a dictionary corresponding to a competitor. The keys to this dictionary are:
• 'name' with the competitor's name associated
• 'note_dist' with which is associated the score obtained by the competitor for the length of his jump. It is known from the question.
• 'notes_style' to which is associated the list of 5 marks obtained by the competitor for the style of his jump.
Thus, if the file passed as an argument consists only of the 4 lines given as an example previously, the function will return:
[{'name': 'Bella', 'notes_style': [18.5, 19.5, 19.5, 19.0, 19.5], 'note_dist': 91.0},
{’nom’: Azhar, ’notes_style’: [19.0, 18.5, 18.5, 18.5, 19.0], ’note_dist’: 83.0},
{'name': Clara, 'notes_style': [17.5, 17.5, 17.5, 18.5, 19.0], 'note_dist': 91.0},
{'name': 'Dalton', 'notes_style': [17.0, 18.5, 18.5, 17.5, 18.0], 'note_dist': 92.5}]
Warning: we remind you that by default everything that is read in a file is of type string.
Step by step
Solved in 2 steps