if __name__=="__main__": economies = { 0: "Survival", 1: "Wealthy Population Center", 2: "Gold and Silver Mining", 3: "Agricultural District", 4: "Pirate Trading Hub", 5: "Naval Fort", 6: "Backwater Port", 7: "National Trading Hub", 8: "Population Center", 9: "Fishing Center", } regions = { 1: "West Acadas [1,1]", 2: "East Acadas [2,1]", 3: "Vraeca Headlands [3,1]", 4: "Vraeca Overland Pass [4,1]", 5: "Whitecliff [5,1]", 6: "Sea of Insanity [6,1]", 7: "Sea of Acada [1,2]", 8: "Starfall Sea [2,2]", 9: "Stone Coast [3,2]", 10:"Southern Tors [4,2]", 11:"Highview [5,2]", 12:"Storm Sea [6,2]", 13:"Deep Sea [1,3]", 14:"West Sea [2,3]", 15:"World Harbor [3,3]", 16:"Oldport [4,3]", 17:"Stag Leap[5,3]", 18:"Deep Sea[6,3]", 19:"Deep Sea [1,4]", 20:"Deep Sea [2,4]", 21:"South Sea [3,4]", 22:"Sea of Swords [4,4]", 23:"The Horn [5,4]", 24:"Star Sea [6,4]", 25:"Damask Coast[1,5]", 26:"Green Sea [2,5]", 27:"Namara Sea [3,5]", 28:"Copper Mountains [4,5]", 29:"Cape of Good Faith [5,5]", 30:"Deep Sea [6,5]", 31:"Inlet of Namara [1,6]", 32:"Emerald Coast [2,6]", 33:"Namara Desert [3,6]", 34:"Namara Salt Flats [4,6]", 35:"Gray Coast [5,6]", 36:"Deep Sea [6,6]" } empires = { 0:"Buccaneers", 1:"Federation of Kaihmer", 2:"Cadari Republic", 3:"Ruesland", 4:"East Acadain Company", 5:"League of Hansa", 6:"Octopon Trading Company", } f = open("towns_orig.txt", "r") sep = ":" outl = [] for line in f: first, name, last = line.split('"') dock_id, econ = first.split() region, empire = last.split() reordered_line = [name + sep + dock_id + sep + economies[int(econ)] + sep + regions[int(region)] + sep + empires[int(empire)] + "\n"] outl += reordered_line outl.sort() outf = open("sorted.txt", "w") outf.writelines(outl) outf.close()