Here's an example. This has nothing to do with Spark though.
>>> list1 = ['SO', 'AE', 'AP'] >>> list2 = ['NM', 'NV', 'OR'] >>> dict1 = {k: "Midwest" for k in list1} >>> dict1 {'SO': 'Midwest', 'AE': 'Midwest', 'AP': 'Midwest'} >>> dict2 = {k: "Northeast" for k in list2} >>> dict2 {'NM': 'Northeast', 'NV': 'Northeast', 'OR': 'Northeast'} >>> dict3 = {**dict1, **dict2} >>> dict3 {'SO': 'Midwest', 'AE': 'Midwest', 'AP': 'Midwest', 'NM': 'Northeast', 'NV': 'Northeast', 'OR': 'Northeast'}
Alternatively, if line dict3 = {**dict1, **dict2} is giving you a SyntaxError (meaning you're using some pretty old Python, i.e. <3.5 or 2.x which is no longer supported), you can merge the dicts like this:
>>> dict3 = dict1.copy() >>> dict3.update(dict2) >>> dict3 {'AP': 'Midwest', 'SO': 'Midwest', 'NM': 'Northeast', 'AE': 'Midwest', 'OR': 'Northeast', 'NV': 'Northeast'}