Andrea Poltronieri

Results 17 comments of Andrea Poltronieri

``` def test_my_enumerate(input_list: object, expected: object): result = my_enumerate(input_list) if result == expected: return True else: return False def my_enumerate(input_list): results = list() position = 0 for item in input_list:...

def linear_search (input_list, value_to_search): # iterate all the items in the input list, # getting also their position on the list for position, item in enumerate(input_list): # check if the...

``` def test_fib(n, expected): result = fib(n) if result == expected: return True else: return False def fib(n): if n

``` from networkx import Graph my_graph = Graph() my_graph.add_node(1, name = "Tim", surname = "Berners-Lee") my_graph.add_node(2, name = "Tom", surname = "Heat") my_graph.add_node(3, name = "Christian", surname = "Bizer") my_graph.add_node(4,...

``` set_hobbit = set({"Frodo", "Sam", "Pippin", "Merry"}) set_magician = set({"Saruman", "Gandalf"}) first_dict = dict() # this creates a new dictionary first_dict["hobbit"] = set_hobbit first_dict["magician"] = set_magician print(first_dict) ``` #output: {'hobbit':...

``` def test_exponentation(base_number, exponent, expected): result = exponentation(base_number, exponent) if expected == result: return True else: return False def exponentation(base_number, exponent): if exponent == 0: return 1 if exponent ==...

``` #test stack def test_stack_from_list(input_list, expected): result = stack_from_list(input_list) if result == expected: return True else: return False from collections import deque def stack_from_list(input_list): output_stack = deque() # Iterate each...

``` from networkx import MultiDiGraph my_cinema_graph = MultiDiGraph() my_cinema_graph.add_node(1, name = "Brad", surname = "Pitt") my_cinema_graph.add_node(2, name = "Eva", surname = "Green") my_cinema_graph.add_node(3, name = "George", surname = "Clooney") my_cinema_graph.add_node(4,...

``` def test_multiplication(n_1, n_2, expected, d=dict()): result = multiplication(n_1, n_2, d=dict()) if result == expected: return True else: return False def multiplication(n_1, n_2, d=dict()): if n_2 not in d: if...

``` my_set = set() # this creates a new set my_set.add("Bilbo") # these 5 lines add five names my_set.add("Frodo") my_set.add("Sam") my_set.add("Pippin") my_set.add("Merry") print(my_set) # the output is {'Bilbo', 'Frodo', 'Pippin',...