(Feb-22-2019, 12:51 PM)anna Wrote: I am able to find all key and values in loop, but its printing only last key value out of loopYes, because you overwrite the previous value. What you print proves exactly that!!!!
#list for BGP prefixes dicts bgp_prefix_list = [] for line in ip_prefix: if 'ip ip-prefix' in line: #dict for BGP prefixes bgp_prefix_dict = {} prefix_name = line.strip().split(' ')[2] subnet = line.strip().split(' ')[6]+"/"+line.strip().split(' ')[7] bgp_subnet = str(IPNetwork(subnet)) bgp_prefix_dict['prefix_name'] = prefix_name bgp_prefix_dict['bgp_subnet'] = bgp_subnet print(bgp_prefix_dict) #### Able to print current dict bgp_prefix_list.append(bgp_prefix_dict) print(bgp_prefix_list)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs