Hi all,
Im pretty new to python and Im learing how to import CSV and make it a dictionary
I made it but I dont know how to remove the headers and the values are in a list and I need them not to lol
this is the code:
this is my output:
Im pretty new to python and Im learing how to import CSV and make it a dictionary
I made it but I dont know how to remove the headers and the values are in a list and I need them not to lol
this is the code:
noc_dict = {} def read_file_noc(file): with open("noc_countries.csv", "r") as my_csv: for line in my_csv: line = line.replace('\n', '') line = line.split(',') noc_dict[line[0]] = line[1:]return noc_dict
this is my output:
Output:{'NOC': ['region'], 'AFG': ['Afghanistan'], 'ALB': ['Albania'], 'ALG': ['Algeria'], 'ASA': ['American Samoa'], 'AND': ['Andorra'], 'ANG': ['Angola'],
While it should be:Output:{'AFG': 'Afghanistan', 'ALB': 'Albania', 'ALG': 'Algeria', 'ASA': 'American Samoa', 'AND': 'Andorra', 'ANG': 'Angola',
I tried to find it online and solve it myself but I couldnt find the answer.. appreciate any help!