I think the following code does what you want:
with open("CountryCodes.csv",'r') as CountryCodes:
genc = (line.split(',') for line in CountryCodes)
c2n = dict((c_fields[0].strip(),c_fields[1].strip())
for c_fields in genc)
with open("CountryData.csv",'r') as CountryData:
gend = (line.split(',') for line in CountryData)
the_data = [ (c2n[d_fields[0].strip()], # data_country_code
int(d_fields[1]), # country_pop
d_fields[2].strip(), # country_area
d_fields[3].strip(), # country_gdp
d_fields[4].strip()) # country_lit_rate
for d_fields in gend ]
the_data.sort(key = lambda x: x[1])
p = 10
for i in xrange(0,len(the_data),p):
if i: raw_input(" Press ENTER to continue\n")
print ('\n'.join("%-10s \t %-10s \t %-10s \t %-10s \t %s"
% el for el in the_data[i:i+p]) )
The dictionary c2n gives the names corresponding to codes.
The population field is certainly a string expressing an integer that doesn't need to be striped, even if there are whitespaces in it (blanks, tabs... not newlines)
.
EDIT
If you're not authorized to use a dictionary but only lists, you cab do like that:
with open("CountryCodes.csv",'r') as CountryCodes:
genc = (line.split(',') for line in CountryCodes)
lic = [map(str.strip,row) for row in genc]
def name_of(x,lic=lic):
for code,name,continent in lic:
if x==code:
return name
with open("CountryData.csv",'r') as CountryData:
gend = (line.split(',') for line in CountryData)
the_data = [ (name_of(d_fields[0].strip()), # data_country_code
int(d_fields[1]), # country_pop
d_fields[2].strip(), # country_area
d_fields[3].strip(), # country_gdp
d_fields[4].strip()) # country_lit_rate
for d_fields in gend ]