Python Forum
changing key names in nested dict
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
changing key names in nested dict
#7
Thumbs Up 
ok got it...thank you for pushing me in the right direction Cool i do this for self educational purposes to make me
a little bit mor python fluent, so sorry for some potential stupid questions.

 #
    # IP's ..
    #
    my_dict = nested_defaultdict(list, 2) 
    ifconfig_output = subprocess.check_output(['/usr/sbin/ifconfig', '-a']).decode('utf-8')
    result = re.findall(r'^(\S+):.*?[\s]+inet ([\d\.]+) netmask ([\w.]+) broadcast ([\d\.]+)', ifconfig_output, re.S | re.M)
    ip_lst = []

    for interface in result:
        if (interface[1] in skip_ip_list):
            continue
        if_name = interface[0]
        ip_addr = interface[1]
        net_mask = dec_netmask(interface[2])
        broad_cast = interface[3]
        r_dns = do_rDNS(interface[1])

        ip_lst.append(("IP", ip_addr))


    my_dict['nodeinfo']['ip'].append(ip_lst)
    print(ip_lst)
    print(my_dict['nodeinfo']['ip'])
        #my_dict['nodeinfo']['IP_LONG'].update({if_name : ip_addr + "/" + net_mask + "/" + broad_cast + "/" + r_dns})
'nodeinfo': {'CLUSTER_NAME': 'JBOSS4',
              ...
              'YUM_REPO': 'IBM',
              'ip': [[['IP', '172.17.10.147'],
                      ['IP', '172.16.88.57'],
                      ['IP', '172.16.12.147']]]},
Reply


Messages In This Thread
changing key names in nested dict - by wardancer84 - Sep-09-2021, 03:23 PM
RE: changing key names in nested dict - by wardancer84 - Sep-10-2021, 08:13 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Updating nested dict list keys tbaror 2 1,916 Feb-09-2022, 09:37 AM
Last Post: tbaror
Star Recursively convert nested dicts to dict subclass Alfalfa 1 3,838 Jan-22-2021, 05:43 AM
Last Post: buran
  Sort a dict in dict cherry_cherry 4 104,334 Apr-08-2020, 12:25 PM
Last Post: perfringo
  convert List of Dicts into a 2 deep Nested Dict rethink 1 4,050 Aug-23-2019, 05:28 PM
Last Post: ichabod801
  Easy way to sort a nested dict Alfalfa 3 6,477 Dec-07-2018, 04:12 PM
Last Post: Alfalfa
  how to create a nested dict.. wardancer84 5 4,858 Nov-23-2018, 04:01 AM
Last Post: Larz60+
  sorting nested dict according to values merlem 6 19,665 Apr-01-2017, 10:01 PM
Last Post: snippsat
  Functions (Arguments Passing,Changing a mutable ,Assignment to Arguments Names) Adelton 2 4,619 Mar-02-2017, 10:23 PM
Last Post: zivoni

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020