import json modern_style = [[["AA","AB","AC","AD","AE","AF","AG","AH","AJ","AK","AL","AM","AN"],"Anglia","Peterborough"],[["AO","AP","AR","AS","AT","AU"],"Anglia","Norwich"],[["AV","AW","AX","AY"],"Anglia","Ipswich"],[["BA","BB","BC","BD","BE","BF","BG","BH","BJ","BK","BL","BM","BN","BO","BP","BR","BS","BT","BU","BV","BW","BX","BY"],"Birmingham","Birmingham"],[["CA","CB","CC","CD","CE","CF","CG","CH","CJ","CK","CL","CM","CN","CO"],"Cymru","Cardiff"],[["CP","CR","CS","CT","CU","CV"],"Cymru","Swansea"],[["CW","CX","CY"],"Cymru","Bangor"],[["DA","DB","DC","DD","DE","DF","DG","DH","DJ","DK"],"Deeside to Shrewsbury","Chester"],[["DL","DM","DN","DO","DP","DR","DS","DT","DU","DV","DW","DX","DY"],"Deeside to Shrewsbury","Shrewsbury"],[["EA","EB","EC","ED","EE","EF","EG","EH","EJ","EK","EL","EM","EN","EO","EP","ER","ES","ET","EU","EV","EW","EX","EY"],"Essex","Chelmsford"],[["FA","FB","FC","FD","FE","FF","FG","FH","FJ","FK","FL","FM","FN","FP"],"Forest and Fens","Nottingham"],[["FR","FS","FT","FV","FW","FX","FY"],"Forest and Fens","Lincoln"],[["GA","GB","GC","GD","GE","GF","GG","GH","GJ","GK","GL","GM","GN","GO"],"Garden of England","Maidstone"],[["GP","GR","GS","GT","GU","GV","GX","GY"],"Garden of England","Brighton"],[["HA","HB","HC","HD","HE","HF","HG","HH","HJ"],"Hampshire and Dorset","Bournemouth"],[["HK","HL","HM","HN","HO","HP","HR","HS","HT","HU","HV","HX","HY"],"Hampshire and Dorset","Portsmouth"],[["HW"],"Hampshire and Dorset","Portsmouth (Used exclusively for the Isle of Wight)"],[["KA","KB","KC","KD","KE","KF","KG","KH","KJ","KK","KL"],"-","Luton"],[["KM","KN","KO","KP","KR","KS","KT","KU","KV","KW","KX","KY"],"-","Northampton"],[["LA","LB","LC","LD","LE","LF","LG","LH","LJ"],"London","Wimbledon"],[["LK","LL","LM","LN","LO","LP","LR","LS","LT"],"London","Stanmore"],[["LU","LV","LW","LX","LY"],"London","Sidcup"],[["MA","MB","MC","MD","ME","MF","MG","MH","MJ","MK","ML","MM","MN","MO","MP","MR","MS","MT","MU","MV","MW","MX","MY"],"Manchester and Merseyside","Manchester"],[["NA","NB","NC","ND","NE","NF","NG","NH","NJ","NK","NL","NM","NN","NO"],"North","Newcastle"],[["NP","NR","NS","NT","NU","NV","NW","NX","NY"],"North","Stockton"],[["OA","OB","OC","OD","OE","OF","OG","OH","OJ","OK","OL","OM","ON","OO","OP","OR","OS","OT","OU","OV","OW","OX","OY"],"Oxford","Oxford"],[["PA","PB","PC","PD","PE","PF","PG","PH","PJ","PK","PL","PM","PN","PO","PP","PR","PS","PT"],"Preston","Preston"],[["PU","PV","PW","PX","PY"],"Preston","Carlisle"],[["RA","RB","RC","RD","RE","RF","RG","RH","RJ","RK","RL","RM","RN","RO","RP","RR","RS","RT","RU","RV","RW","RX","RY"],"Reading","Reading"],[["SA","SB","SC","SD","SE","SF","SG","SH","SJ"],"Scotland","Glasgow"],[["SK","SL","SM","SN","SO"],"Scotland","Edinburgh"],[["SP","SR","SS","ST"],"Scotland","Dundee"],[["SU","SV","SW"],"Scotland","Aberdeen"],[["SX","SY"],"Scotland","Inverness"],[["VA","VB","VC","VD","VE","VF","VG","VH","VJ","VK","VL","VM","VN","VO","VP","VR","VS","VT","VU","VV","VW","VX","VY"],"Severn Valley","Worcester"],[["WA","WB","WC","WD","WE","WF","WG","WH","WJ"],"West of England","Exeter"],[["WK","WL"],"West of England","Truro"],[["WM","WN","WO","WP","WR","WS","WT","WU","WV","WW","WX","WY"],"West of England","Bristol"],[["YA","YB","YC","YD","YE","YF","YG","YH","YJ","YK"],"Yorkshire","Leeds"],[["YL","YM","YN","YO","YP","YR","YS","YT","YU"],"Yorkshire","Sheffield"],[["YV","YW","YX","YY"],"Yorkshire","Beverley"]] legacy_style = {"A": "London","AA": "Bournemouth","AB": "Worcester","AC": "Coventry","AD": "Gloucester","AE": "Bristol","AF": "Truro","AG": "Hull","AH": "Norwich","AJ": "Middlesbrough","AK": "Sheffield","AL": "Nottingham","AM": "Swindon","AN": "Reading","AO": "Carlisle","AP": "Brighton","AR": "Chelmsford","AS": "Inverness","AT": "Hull","AU": "Nottingham","AV": "Peterborough","AW": "Shrewsbury","AX": "Cardiff","AY": "Leicester","AZ": "Belfast","B": "Lancashire","BA": "Manchester","BB": "Newcastle-upon-Tyne","BC": "Leicester","BD": "Northampton","BE": "Lincoln","BF": "Stoke-on-Trent","BG": "Liverpool","BH": "Luton","BJ": "Ipswich","BK": "Portsmouth","BL": "Reading","BM": "Luton","BN": "Manchester or Bolton","BO": "Cardiff","BP": "Portsmouth","BR": "Newcastle-upon-Tyne","BS": "Aberdeen","BT": "Leeds","BU": "Manchester","BV": "Preston","BW": "Oxford","BX": "Haverfordwest","BY": "London (North-West)","BZ": "County Down","C": "West Yorkshire","CA": "Chester","CB": "Manchester","CC": "Bangor","CD": "Brighton","CE": "Peterborough","CF": "Reading","CG": "Bournemouth","CH": "Nottingham","CJ": "Gloucester","CK": "Preston","CL": "Norwich","CM": "Liverpool","CN": "Newcastle-upon-Tyne","CO": "Exeter","CP": "Huddersfield","CR": "Southampton ","CS": "Glasgow","CT": "Lincoln","CU": "Newcastle-upon-Tyne","CV": "Truro","CW": "Preston","CX": "Huddersfield","CY": "Swansea","CZ": "Belfast","D": "Kent","DA": "Birmingham","DB": "Manchester","DC": "Middlesbrough","DD": "Gloucester","DE": "Haverfordwest","DF": "Gloucester","DG": "Gloucester","DH": "Dudley","DJ": "Liverpool","DK": "Rochdale, later Manchester","DL": "Portsmouth","DM": "Chester","DN": "Leeds","DO": "Lincoln","DP": "Reading","DR": "Exeter","DS": "Glasgow","DT": "Sheffield","DU": "Coventry","DV": "Exeter","DW": "Cardiff","DX": "Ipswich","DY": "Brighton","DZ": "County Antrim","E": "Staffordshire","EA": "Dudley","EB": "Peterborough","EC": "Preston","ED": "Liverpool","EE": "Lincoln","EF": "Middlesbrough","EG": "Peterborough","EH": "Stoke-on-Trent","EJ": "Haverfordwest","EK": "Liverpool","EL": "Bournemouth","EM": "Liverpool","EN": "Bury, later Manchester","EO": "Preston","EP": "Swansea","ER": "Peterborough","ES": "Dundee","ET": "Sheffield","EU": "Bristol","EV": "Chelmsford","EW": "Peterborough","EX": "Norwich","EY": "Bangor","EZ": "Belfast","F": "Essex","FA": "Stoke-on-Trent","FB": "Bristol","FC": "Oxford","FD": "Dudley","FE": "Lincoln","FF": "Bangor","FG": "Brighton","FH": "Gloucester","FJ": "Exeter","FK": "Dudley","FL": "Peterborough","FM": "Chester","FN": "Maidstone","FO": "Gloucester","FP": "Leicester","FR": "Preston","FS": "Edinburgh","FT": "Newcastle-upon-Tyne","FU": "Lincoln","FV": "Preston","FW": "Lincoln","FX": "Bournemouth","FY": "Liverpool","FZ": "Belfast","G": "Glasgow","GA": "Glasgow","GB": "Glasgow","GC": "London (South-West)","GD": "Glasgow","GE": "Glasgow","GF": "London (South-West)","GG": "Glasgow","GH": "London (South-West)","GJ": "London (South-West)","GK": "London (South-West)","GL": "Truro","GM": "Reading","GN": "London (South-West)","GO": "London (South-West)","GP": "London (South-West)","GR": "Newcastle-upon-Tyne","GS": "Luton","GT": "London (South-West)","GU": "London (South-East)","GV": "Ipswich","GW": "London (South-East)","GX": "London (South-East)","GY": "London (South-East)","GZ": "Belfast","H": "London","HA": "Dudley","HB": "Cardiff","HC": "Brighton","HD": "Huddersfield","HE": "Sheffield","HF": "Liverpool","HG": "Preston","HH": "Carlisle","HJ": "Chelmsford","HK": "Chelmsford","HL": "Sheffield","HM": "London (Central)","HN": "Middlesbrough","HO": "Bournemouth","HP": "Coventry","HR": "Swindon","HS": "Glasgow","HT": "Bristol","HU": "Bristol","HV": "London (Central)","HW": "Bristol","HX": "London (Central)","HY": "Bristol","J": "Durham","JA": "Manchester","JB": "Reading","JC": "Bangor","JD": "London (Central)","JE": "Peterborough","JF": "Leicester","JG": "Maidstone","JH": "Reading","JJ": "Maidstone","JK": "Brighton","JL": "Lincoln","JM": "Reading","JN": "Chelmsford","JO": "Oxford","JP": "Liverpool","JR": "Newcastle-upon-Tyne","JS": "Inverness","JT": "Bournemouth","JU": "Leicester","JV": "Lincoln","JW": "Birmingham","JX": "Huddersfield","JY": "Exeter","JZ": "County Down","K": "Liverpool","KA": "Liverpool","KB": "Liverpool","KC": "Liverpool","KD": "Liverpool","KE": "Maidstone","KF": "Liverpool","KG": "Cardiff","KH": "Hull","KJ": "Maidstone","KK": "Maidstone","KL": "Maidstone","KM": "Maidstone","KN": "Maidstone","KO": "Maidstone","KP": "Maidstone","KR": "Maidstone","KS": "Edinburgh","KT": "Maidstone","KU": "Sheffield","KV": "Coventry","KW": "Sheffield","KX": "Luton","KY": "Sheffield","KZ": "County Antrim","L": "Glamorganshire","LA": "London (North-West) (used for London County Council before 1965)","LB": "London (North-West) (used for London County Council before 1965)","LC": "London (North-West) (used for London County Council before 1965)","LD": "London (North-West) (used for London County Council before 1965)","LE": "London (North-West) (used for London County Council before 1965)","LF": "London (North-West) (used for London County Council before 1965)","LG": "Chester","LH": "London (North-West) (used for London County Council before 1965)","KJ": "Bournemouth","LK": "London (North-West) (used for London County Council before 1965)","LL": "London (North-West) (used for London County Council before 1965)","LM": "London (North-West) (used for London County Council before 1965)","LN": "London (North-West) (used for London County Council before 1965)","LO": "London (North-West) (used for London County Council before 1965)","LP": "London (North-West) (used for London County Council before 1965)","LR": "London (North-West) (used for London County Council before 1965)","LS": "Edinburgh","LT": "London (North-West) (used for London County Council before 1965)","LU": "London (North-West) (used for London County Council before 1965)","LV": "Liverpool","LW": "London (North-West) (used for London County Council before 1965)","LX": "London (North-West) (used for London County Council before 1965)","LY": "London (North-West) (used for London County Council before 1965)","LZ": "County Armagh","M": "Cheshire","MA": "Chester","MB": "Chester","MC": "London (North-East) (used for Middlesex before 1965)","MD": "London (North-East) (used for Middlesex before 1965)","ME": "London (North-East) (used for Middlesex before 1965)","MF": "London (North-East) (used for Middlesex before 1965)","MG": "London (North-East) (used for Middlesex before 1965)","MH": "London (North-East) (used for Middlesex before 1965)","MJ": "Luton","MK": "London (North-East) (used for Middlesex before 1965)","ML": "London (North-East) (used for Middlesex before 1965)","MM": "London (North-East) (used for Middlesex before 1965)","MN": "used in the Isle of Man","MO": "Reading","MP": "London (North-East) (used for Middlesex before 1965)","MR": "Swindon","MS": "Edinburgh","MT": "London (North-East) (used for Middlesex before 1965)","MU": "London (North-East) (used for Middlesex before 1965)","MV": "London (North-East) (used for Middlesex before 1965)","MW": "Swindon","MX": "London (North-East) (used for Middlesex before 1965)","MY": "London (North-East) (used for Middlesex before 1965)","MZ": "Belfast","N": "Manchester","NA": "Manchester","NB": "Manchester","NC": "Manchester","ND": "Manchester","NE": "Manchester","NF": "Manchester","NG": "Norwich","NH": "Northampton","NJ": "Brighton","NK": "Luton","NL": "Newcastle-upon-Tyne","NM": "Luton","NN": "Nottingham","NO": "Chelmsford","NP": "Worcester","NR": "Leicester","NS": "Glasgow","NT": "Shrewsbury","NU": "Nottingham","NV": "Northampton","NW": "Leeds","NX": "Dudley","NY": "Cardiff","NZ": "County Londonderry/Derry","O": "Birmingham","OA": "Birmingham","OB": "Birmingham","OC": "Birmingham","OD": "Exeter","OE": "Birmingham","OF": "Birmingham","OG": "Birmingham","OH": "Birmingham","OI": "Belfast","OJ": "Birmingham","OK": "Birmingham","OL": "Birmingham","OM": "Birmingham","ON": "Birmingham","OO": "Chelmsford","OP": "Birmingham","OR": "Portsmouth","OS": "Glasgow","OT": "Portsmouth","OU": "Bristol","OV": "Birmingham","OW": "Southampton ","OX": "Birmingham","OY": "London (North-West)","OZ": "Belfast","P": "Surrey","PA": "Guildford","PB": "Guildford","PC": "Guildford","PD": "Guildford","PE": "Guildford","PF": "Guildford","PG": "Guildford","PH": "Guildford","PJ": "Guildford","PK": "Guildford","PL": "Guildford","PM": "Guildford","PN": "Brighton","PO": "Portsmouth (GPO formerly used for General Post Office vehicles)","PP": "Luton","PR": "Bournemouth","PS": "Aberdeen","PT": "Newcastle-upon-Tyne","PU": "Chelmsford","PV": "Ipswich","PW": "Norwich","PX": "Portsmouth","PY": "Middlesbrough","PZ": "Belfast","R": "Derbyshire","RA": "Nottingham","RB": "Nottingham","RC": "Nottingham","RD": "Reading","RE": "Stoke-on-Trent","RF": "Stoke-on-Trent","RG": "Newcastle-upon-Tyne","RH": "Hull","RJ": "Manchester","RK": "London (North-West)","RL": "Truro","RM": "Carlisle","RN": "Preston","RO": "Luton","RP": "Northampton","RR": "Nottingham","RS": "Aberdeen","RT": "Ipswich","RU": "Bournemouth","RV": "Portsmouth","RW": "Coventry","RX": "Reading","RY": "Leicester","RZ": "County Antrim","S": "Edinburgh","SA": "Aberdeen","SB": "Glasgow","SC": "Edinburgh","SD": "Glasgow","SE": "Aberdeen","SF": "Edinburgh","SG": "Edinburgh","SH": "Edinburgh","SJ": "Glasgow","SK": "Inverness","SL": "Dundee","SM": "Carlisle","SN": "Dundee","SO": "Aberdeen","SP": "Dundee","SR": "Dundee","SS": "Aberdeen","ST": "Inverness","SU": "Glasgow","SW": "Carlisle","SX": "Edinburgh","T": "Devon","TA": "Exeter","TB": "Liverpool","TC": "Bristol","TD": "Manchester","TE": "Manchester","TF": "Reading","TG": "Cardiff","TH": "Swansea","TJ": "Liverpool","TK": "Exeter","TL": "Lincoln","TM": "Luton","TN": "Newcastle-upon-Tyne","TO": "Nottingham","TP": "Portsmouth","TR": "Southampton ","TS": "Dundee","TT": "Exeter","TU": "Chester","TV": "Nottingham","TW": "Chelmsford","TX": "Cardiff","TY": "Newcastle-upon-Tyne","TZ": "Belfast","U": "Leeds","UA": "Leeds","UB": "Leeds","UC": "London (Central)","UD": "Oxford","UE": "Dudley","UF": "Brighton","UG": "Leeds","UH": "Cardiff","UI": "County Londonderry/Derry","UJ": "Shrewsbury","UK": "Birmingham","UL": "London (Central)","UM": "Leeds","UN": "Exeter","UO": "Exeter","UP": "Newcastle-upon-Tyne","UR": "Luton","US": "Glasgow","UT": "Leicester","UU": "London (Central)","UV": "London (Central)","UW": "London (Central)","UX": "Shrewsbury","UY": "Worcester","UZ": "Belfast","V": "Lanarkshire","VA": "Peterborough","VB": "Maidstone","VC": "Coventry","VD": "Lanarkshire/Luton","VE": "Peterborough","VF": "Norwich","VG": "Norwich","VH": "Huddersfield","VJ": "Gloucester","VK": "Newcastle-upon-Tyne","VL": "Lincoln","VM": "Manchester","VN": "Middlesbrough","VO": "Nottingham","VP": "Birmingham","VR": "Manchester","VS": "Luton","VT": "Stoke-on-Trent","VU": "Manchester","VV": "Northampton","VW": "Chelmsford","VX": "Chelmsford","VY": "Leeds","VZ": "County Tyrone","W": "Sheffield","WA": "Sheffield","WB": "Sheffield","WC": "Chelmsford","WD": "Dudley","WE": "Sheffield","WF": "Sheffield","WG": "Sheffield","WH": "Manchester or Bolton","WJ": "Sheffield","WK": "Coventry","WL": "Oxford","WM": "Liverpool","WN": "Swansea","WO": "Cardiff","WP": "Worcester","WR": "Leeds","WS": "Bristol","WT": "Leeds","WU": "Leeds","WV": "Brighton","WW": "Leeds","WX": "Leeds","WY": "Leeds","WZ": "Belfast","X": "Northumberland","XI": "Belfast","XZ": "County Armagh","Y": "Somerset","YA": "Taunton","YB": "Taunton","YC": "Taunton","YD": "Taunton","YE": "London (Central)","YF": "London (Central)","YG": "Leeds","YH": "London (Central)","YJ": "Brighton","YK": "London (Central)","YL": "London (Central)","YM": "London (Central)","YN": "London (Central)","YO": "London (Central)","YP": "London (Central)","YR": "London (Central)","YS": "Glasgow","YT": "London (Central)","YU": "London (Central)","YV": "London (Central)","YW": "London (Central)","YX": "London (Central)","YY": "London (Central)","YZ": "County Londonderry",} area_codes = {"legacy_style":{}, "modern_style":{}} for i in modern_style: for y in i[0]: area_codes["modern_style"][y] = [i[1], i[2]] for i in legacy_style: area_codes["legacy_style"][i] = legacy_style[i] with open("2013_area_codes.json", "w") as f: json.dump(area_codes, f, indent=4)