Create a new dictionary with the key-value pair from values in a list of dictionaries based on matches from a separate list

Advertisements I am trying to get a new dictionary with the k: v pair from values in a list of dictionary based on matches from a separate list. The casing is different. My data looks like this: list_of_dicts = [ {‘fieldname’: ‘Id’, ‘source’: ‘microsoft’, ‘nullable’: True, ‘type’: ‘int’}, {‘fieldname’: ‘FirstName’, ‘source’: ‘microsoft’, ‘nullable’: True, ‘type’:… Read More Create a new dictionary with the key-value pair from values in a list of dictionaries based on matches from a separate list

how can I create a nested dictionary with use a same key in list of dictionaries

Advertisements I have this dictionary: data=[{‘first’: ‘0’, ‘last’: ‘hg01’, ‘pay’: 0}, {‘first’: ‘0’, ‘last’: ‘hg75’, ‘pay’: 15}, {‘first’: ‘0’, ‘last’: ‘hg0’, ‘pay’: 1}, {‘first’: ‘0’, ‘last’: ‘hg9’, ‘pay’: 13}, {‘first’: ‘0’, ‘last’: ‘hg0’, ‘pay’: 0}, {‘first’: ‘0’, ‘last’: ‘hg’, ‘pay’: 13}, {‘first’: ‘0’, ‘last’: ‘hg76’, ‘pay’: 0}, {‘first’: ‘0’, ‘last’: ‘hg1’, ‘pay’: 9}, {‘first’: ‘0’,… Read More how can I create a nested dictionary with use a same key in list of dictionaries

Python Dict Comprehension retrieve value from 1 dataframe column if match another column value

Advertisements I have a dataframe and there are 2 columns ["country"] and ["city"] which basically informs of the country and their cities. I need to create a dict using dict comprehensions, to get as a key, the country and as values, a list of the city/cities (some of them only have one city, others many).… Read More Python Dict Comprehension retrieve value from 1 dataframe column if match another column value

convert nested tuples in lists into a dictionary and add new key values

Advertisements i am trying to convert these nested tuples into a dictionary country_list = [[(‘Finland’, ‘Helsinki’)], [(‘Sweden’, ‘Stockholm’)], [(‘Norway’, ‘Oslo’)]] and to add custom key values to such as the output would be [{‘country’: ‘FINLAND’, ‘city’: ‘HELSINKI’}, {‘country’: ‘SWEDEN’, ‘city’: ‘STOCKHOLM’}, {‘country’: ‘NORWAY’, ‘city’: ‘OSLO’}] i’ve done this: new_country=[list(country) for sublist in country_list for country… Read More convert nested tuples in lists into a dictionary and add new key values

Change keys in a dictionary

Advertisements I have this dictionary. maximo = {‘CodChamado’: 50, ‘_14984|Top Down:’: 0, ‘_14985|Hierarquia solicitante:’: 0} And I want to change these keys "_14984|Top Down:" and "_14985|Hierarquia solicitante:" to new_key = [‘Campo Extra|Top Down:’, ‘Campo Extra|Hierarquia solicitante:’] The result of that is the new dictionary: new_maximo = {‘CodChamado’: 50, ‘Campo Extra|Top Down:’: 0, ‘Campo Extra|Hierarquia solicitante:’:… Read More Change keys in a dictionary

Converting a dictionary of lists to a pandas.DataFrame using predefined headers

Advertisements I have a dictionary that looks like the following: date_pair_dict = { "15-02-2022 15-02-2022": ["key 1 val 1", "key 1 val 2", "key 1 val 3"], "15-02-2022 16-02-2022": ["key 2 val 1", "key 2 val 2", "key 2 val 3"], "16-02-2022 16-02-2022": ["key 3 val 1", "key 3 val 2", "key 3 val 3"],… Read More Converting a dictionary of lists to a pandas.DataFrame using predefined headers

Dictionary Comprehension within a List Comprehension

Advertisements I have a list of dictionaries, that I’m modifying values in. I have a for loop that works as expected. show_mac = [{‘mac’: ‘0000.0000.0000’, ‘port’: ‘GigabitEthernet1/1’, ‘type’: ‘dynamic’, ‘vlan’: ‘1’}, {‘mac’: ‘0000.0000.0000’, ‘port’: ‘TenGigabitEthernet2/1’, ‘type’: ‘dynamic’, ‘vlan’: ‘1’}, {‘mac’: ‘0000.0000.0000’, ‘port’: ‘Port-channel1’, ‘type’: ‘dynamic’, ‘vlan’: ‘1’}] for d in show_mac: for k, v in… Read More Dictionary Comprehension within a List Comprehension

Flatten list of dictionaries into dataframe columns

Advertisements I have the following data which contain lists of dictionaries data= [ {‘Time’: 18057610.0, ‘Flux’: [{‘V0’: -1.4209e-15}, {‘V1’: 2.7353e-16}, {‘V2’: 1.1935e-15}, {‘V3’: 1.1624}, {‘V4’: -6.1692e-15}, {‘V5’: 3.2218e-15}]}, {‘Time’: 18057620.4, ‘Flux’: [{‘V0’: 2.4377e-16}, {‘V1’: -6.2809e-15}, {‘V2’: 1.6456e-15}, {‘V3’: 1.1651}, {‘V4’: 1.7147e-15}, {‘V5’: 9.8872e-16}]}, {‘Time’: 18057631.1, ‘Flux’: [{‘V0’: 4.1124e-15}, {‘V1’: 1.5598e-15}, {‘V2’: -2.325e-16}, {‘V3’: 1.1638}, {‘V4’:… Read More Flatten list of dictionaries into dataframe columns