3
3
4
4
# This module contains codes about algorithms complexity as to estimate the time
5
5
# an algorithm will take to be run.
6
- # Why do we find it usable ? Because, knowing this kind of information tells you if your code
7
- # or solution is efficient or not ; it helps you not to fall trying to run such a code.
6
+ # Why do we find it usable ?
7
+ # Because, knowing this kind of information tells you if your code or solution is
8
+ # efficient or not ; it helps you not to fall trying to run such a code.
8
9
9
10
10
11
def calc (operations : dict ) -> float :
11
12
"""
12
13
calc(operation: dict) -> float:
13
- This function aims to calculate how long an algorithm take, knowing only primary operations
14
- :param operations: A dictionary where the values are tuples, consisting of the number of times
15
- an operation is performed and its execution time, and the key should
16
- preferably be the name of the operation for better clarity and usability.
17
- :return: the time needed for the execution of this algorithm(if format is okey for "operations") or 0
14
+ This function aims to calculate how long an algorithm take,
15
+ knowing only primary operations
16
+ :param operations:
17
+ A dictionary where the values are tuples, consisting of the number of times
18
+ an operation is performed and its execution time, and the key should,
19
+ preferably, be the name of the operation for better clarity and usability.
20
+ :return: the time needed for the execution of this algorithm
18
21
#>>> operations1 = {"addition":(2, 0.1), "subtraction":(1, 0.2)}
19
22
#>>> operations2 = {"addition":(2, 0.1), "subtraction":(1, 0.2, 1)}
20
23
#>>> calc(operations1)
@@ -24,8 +27,10 @@ def calc(operations: dict) -> float:
24
27
"""
25
28
temps = 0
26
29
for couple in operations .values ():
30
+ # Case you give a shorter or a longer tuple
27
31
if len (couple ) != 2 :
28
32
return 0
33
+ # Otherwise
29
34
temps += couple [0 ] * couple [1 ]
30
35
31
36
return temps
0 commit comments