EMI Exercise Problem

Hello Folks,
I have created different functions for the exercise problem of EMI calculation but I am not getting how
to combine these all functions to get a single function to form a dictionary …
Can you guys please help me out?

def readlines(path):
    with open(path, 'r') as f:
        lines = f.readlines()
        return lines
def parse_values(data_line):
    result = []
    for item in data_line.strip().split(','):
        if item == '':
            result.append(0.00)
        else:
            result.append(float(item))
    return result
def list_of_parameter(parameters): # Parameter will be number like 1, 2, 3 to get list of amount, rate of intrest, down payment etc.
    lists = []
    for data_line in lines[1:]:
        values_in_data_line = parse_values(data_line)
        lists.append(values_in_data_line[parameters])           
    return lists
def all_list(no_of_column):
    final_list = []
    for i in range(0, no_of_column):
        single_list = list_of_parameter(i)
        final_list.append(single_list)
    return final_list
def parse_headers(header_line):
    return header_line.strip().split(',')
def parse_headers(header_line):
    return header_line.strip().split(',')

def parse_values(file_lines):
    lines = []
    for file_line in file_lines[1:]:
        line = file_line.strip().split(',')
        lines.append(line)
    return lines 

def values_of_corresponding_header(headers,list_of_values):
    lines_list = []
    i = 0
    while i<= (len(headers)-1):
        lst = []
        for line in list_of_values:
            if line[i] == '':
                lst.append(0.0)
            else:
                try:
                    lst.append(float(line[i]))
                except ValueError:
                    lst.append(line[i]) 
        lines_list.append(lst)
        i = i + 1
    return lines_list

def create_item_dict(headers, lines_list):
    result = {}
    for header, line_list in zip(headers, lines_list):
        result[header] = line_list   
    return result

def read_csv_columnar(path):
    # open the file in read mode
    with open(path, 'r') as f:
        # Get a list of lines
        lines = f.readlines()
        # Parse the header
        headers = parse_headers(lines[0])
        # parse the remaining lines
        values = parse_values(lines)
        # putting values of commomn header under a list
        lists_of_common_header = values_of_corresponding_header(headers,values)
        # Create a dictionary using values & headers
        result = create_item_dict(headers, lists_of_common_header)
    return result
1 Like