jpdiazpardo commited on
Commit
49e7cd5
1 Parent(s): 325a38f

Delete dictionaries.py

Browse files
Files changed (1) hide show
  1. dictionaries.py +0 -36
dictionaries.py DELETED
@@ -1,36 +0,0 @@
1
- def transform_dict(list_dic):
2
- '''Takes a list of dictionaries and converts the values inside the 'label' key
3
- into a new key and assigns the values of the 'score' key into the new values of the new dictionary.
4
- returns: dictionary'''
5
-
6
- new_dicts = {}
7
- for original_dict in list_dic:
8
- key = original_dict['label']
9
- value = original_dict['score']
10
- new_dicts[key] = value
11
-
12
- return new_dicts
13
-
14
-
15
- def calculate_average(list_of_dicts):
16
- '''Calculates the average value across all keys from a list of dictionaries'''
17
- sum_dict = {}
18
- count_dict = {}
19
-
20
- # Step 1 and 2
21
- for dictionary in list_of_dicts:
22
- for key, value in dictionary.items():
23
- if key in sum_dict:
24
- sum_dict[key] += value
25
- count_dict[key] += 1
26
- else:
27
- sum_dict[key] = value
28
- count_dict[key] = 1
29
-
30
- average_dict = {}
31
-
32
- # Step 5
33
- for key in sum_dict:
34
- average_dict[key] = sum_dict[key] / count_dict[key]
35
-
36
- return average_dict