Category : function

I am trying to implement a simple BFS code. Code: def initalizeVertex(): n = int(input(‘Enter the no. of vertices.n’)) for vertex in range(n): Vertex.append(vertex) node_adjacency[vertex] = [] def initalizeUndirectedEdges(): n = int(input("Enter the no. of edges.n")) print("Enter the space seperated edges.") for i in range(n): a,b = map(int,input().split()) node_adjacency[a].append(b) node_adjacency[b].append(a) def bfs(): current_level = 1 ..

Read more

I have this loop: for dt in AllDates: data = importdata(location, dt, Curve, max_maturity = ’30Y’) fwdrate = interpolate(data, ‘1y’, ‘1y’) It takes each date from AllDates, imports the data for that date and then calculates a set of forward rates for said date. The forward rates are then appended in a dictionary. It does ..

Read more

I am new to functions and I am trying to write a function that returns the number of days between two dates: My attempt: import datetime from dateutil.parser import parse def get_x_days_ago (date_from, current_date = None): td = current_date – parse(date_from) if current_date is None: current_date = datetime.datetime.today() else: current_date = datetime.datetime.strptime(date_from, "%Y-%m-%d") return td.days ..

Read more