revised version:
import os
import time
start = time.time()
from lxml import etree
p1,p2,p3,p4,p5,p6,p7,p8,p9 = 0,0,0,0,0,0,0,0,0
pop1, pop2, pop3, pop4, pop5, pop6, pop7, pop8, pop9 = 0,0,0,0,0,0,0,0,0
def count(p):
global p1,p2,p3,p4,p5,p6,p7,p8,p9,pop1,pop2,pop3,pop4,pop5,pop6,pop7,pop8,pop9,derp
for x in xrange(0,len(derp)):
if p2 < 5590 and derp[x][7].text == 'The North Pacific':
pop2 = pop2 + int(derp[x][8].text)
p2 = p2 + 2
elif p4 < 5100 and derp[x][7].text == 'The East Pacific':
pop4 = pop4 + int(derp[x][8].text)
p4 = p4 + 4
elif p5 < 4929 and derp[x][7].text == 'The West Pacific':
pop5 = pop5 + int(derp[x][8].text)
p5 = p5 + 5
elif p6 < 1424 and derp[x][7].text == 'The Rejected Realms':
pop6 = pop6 + int(derp[x][8].text)
p6 = p6 + 6
elif p9 < 3299 and derp[x][7].text == 'Lazarus':
pop9 = pop9 + int(derp[x][8].text)
p9 = p9 + 9
elif p1 < 4928 and derp[x][7].text == 'The Pacific':
pop1 = pop1 + int(derp[x][8].text)
p1 = p1 + 1
elif p8 < 2774 and derp[x][7].text == 'Osiris':
pop8 = pop8 + int(derp[x][8].text)
p8 = p8 + 8
elif p3 < 4963 and derp[x][7].text == 'The South Pacific':
pop3 = pop3 + int(derp[x][8].text)
p3 = p3 + 3
elif p7 < 2779 and derp[x][7].text == 'Balder':
pop7 = pop7 + int(derp[x][8].text)
p7 = p7 + 7
print pop2/1000,pop4/1000,pop5/1000,pop6/1000,pop9/1000,pop1/1000,pop8/1000,pop3/1000,pop7/1000, p
for x in xrange(1,7):
filename = 'nations'+str(x)+'.xml'
herp = open(filename, 'r')
derp = (etree.parse(herp)).getroot()
herp.close()
p = x
count(p)
print pop1, 'The Pacific'
print pop2, 'The North Pacific'
print pop3, 'The South Pacific'
print pop4, 'The East Pacific'
print pop5, 'The West Pacific'
print pop6, 'The Rejected Realms'
print pop7, 'Balder'
print pop8, 'Osiris'
print pop9, 'Lazarus'
print pop1+pop2+pop3+pop4+pop5+pop6+pop7+pop8+pop9, 'Total'
print 'time', time.time()-start
derp = None
os.system('pause')
os.system('pause')
os.system('pause')