I was given two files. file1 contains a list of country names and their continent such as:
Country,Continent
China,Asia
United States of America,North America
Brazil,South America
and file2 contains a list of country names and their population and areas, such as:
Country|Population|Area
China|1,339,190,000|9,596,960.00
United States of America|309,975,000|9,629,091.00
Brazil|193,364,000|8,511,965.00
I wanted to create two dictionaries, one for file1 and one for file2, then I wanted to combine all the values that has the same key. My final output should be something like this:
China:[193364000, 8511965.00, Asia]
Where the population is an integer and area is float
I made two dictionaries, however I have no idea how to combine the values together.
Here is my code:
#first dictionary
Continent = {}
file2 = open("file2.txt", "r")
for i in file2:
file2 = i.strip
parts2 = i.split(",")
Continent[parts2[0]] = parts2[1]
#Second dictionary
Information = {}
file1 = open("file1.txt", "r")
for j in file1:
file1 = j.strip
part1 = j.split("|")
#Strip "," off from the values so that it's an intger/float
part1[1] = part1[1].replace(",", "")
part1[2] = part1[2].replace(",", "")
Information[part1[0]] = [part1[1], part1[2]]