@@ -16,48 +16,80 @@ def control(anime: list(str)) -> None:
16
16
17
17
def empty_list_by_hand (anime : list (str )) -> None :
18
18
"""
19
- Tests the performance of emptying a list by hand.
19
+ Empties a list by repeatedly removing elements from a list.
20
20
21
21
:param anime: a list of anime
22
22
"""
23
23
anime = anime .copy ()
24
24
while anime :
25
25
anime .pop ()
26
26
27
- def empty_list_by_assignment (anime ):
27
+ def empty_list_by_assignment (anime : list (str )) -> None :
28
+ """
29
+ Empties a list by reassigning the reference.
30
+
31
+ :param anime: a list of anime
32
+ """
28
33
anime = anime .copy ()
29
34
anime = [] # Wouldn't actually work as a function
30
35
31
- def empty_list_by_clear (anime ):
36
+ def empty_list_by_clear (anime : list (str )) -> None :
37
+ """
38
+ Empties a list by calling the clear method.
39
+
40
+ :param anime: a list of anime
41
+ """
32
42
anime = anime .copy ()
33
43
anime .clear ()
34
44
35
- def empty_list_by_del (anime ):
45
+ def empty_list_by_del (anime : list (str )) -> None :
46
+ """
47
+ Empties a list by deleting a slice of the list.
48
+
49
+ :param anime: a list of anime
50
+ """
36
51
anime = anime .copy ()
37
52
del anime [:]
38
53
39
- def empty_list_by_slice_assignment (anime ):
54
+ def empty_list_by_slice_assignment (anime : list (str )) -> None :
55
+ """
56
+ Empties a list by replacing a slice of the list with an empty list.
57
+
58
+ :param anime: a list of anime
59
+ """
40
60
anime = anime .copy ()
41
61
anime [:] = []
42
62
43
- def empty_list_by_multiplication (anime ):
63
+ def empty_list_by_multiplication (anime : list (str )) -> None :
64
+ """
65
+ Empties a list by multiplication.
66
+
67
+ :param anime: a list of anime
68
+ """
44
69
anime = anime .copy ()
45
70
anime *= 0 # Also, would not work as a function
46
71
47
- test_bench (
48
- [
49
- control ,
50
- empty_list_by_hand ,
51
- empty_list_by_assignment ,
52
- empty_list_by_clear ,
53
- empty_list_by_del ,
54
- empty_list_by_slice_assignment ,
55
- empty_list_by_multiplication
56
- ],
57
- {
58
- "Empty List" : [[]],
59
- "One Item List" : [["Your Lie in April" ]],
60
- "Small List" : [["My Hero Academia" , "Attack on Titan" , "Steins;Gate" ]],
61
- "Large List" : [["One Punch Man" ] * 100 ]
62
- }
63
- )
72
+ def main () -> None :
73
+ """
74
+ Tests the performance of all the functions defined in this file.
75
+ """
76
+ test_bench (
77
+ [
78
+ control ,
79
+ empty_list_by_hand ,
80
+ empty_list_by_assignment ,
81
+ empty_list_by_clear ,
82
+ empty_list_by_del ,
83
+ empty_list_by_slice_assignment ,
84
+ empty_list_by_multiplication
85
+ ],
86
+ {
87
+ "Empty List" : [[]],
88
+ "One Item List" : [["Your Lie in April" ]],
89
+ "Small List" : [["My Hero Academia" , "Attack on Titan" , "Steins;Gate" ]],
90
+ "Large List" : [["One Punch Man" ] * 100 ]
91
+ }
92
+ )
93
+
94
+ if __name__ == "__main__" :
95
+ main ()
0 commit comments