Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Iterate a tuple with dict inside
#1
My output is below, its tuple inside dict, help iterate

for interface in result["interfaces"].items():
print(interface)


Output:
('Eth-Trunk1.1908', {'description': 'EXT/ILL/830400/KAVERI INFORMATICS PRIVATE LIMITED/12005830400/NOIDA/2MB/P2M/3333', 'qos-profile': '2Mb', 'vlan-type': '1908', 'address': '14.98.85.29', 'netmask': '255.255.255.252', 'network': '14.98.85.28/30'}) ('Eth-Trunk1.1909', {'description': 'EXT/ILL/830166/KOMMLABS DEZIGN PRIVATE LIMITED/12005830166/NOIDA/10MB/P2M/3333', 'qos-profile': '10Mb', 'vlan-type': '1909', 'address': '14.98.85.41', 'netmask': '255.255.255.252', 'network': '14.98.85.40/30'}) ('Eth-Trunk1.1910', {'description': 'EXT/ILL/828573/ROHA HOUSING FINANCE PRIVATE LIMITED/12005828573/P2M/10MBPS/3333', 'qos-profile': '10Mb', 'vlan-type': '1910', 'address': '14.98.79.29', 'netmask': '255.255.255.252', 'network': '14.98.79.28/30'}) ('Eth-Trunk1.1911', {'description': 'EXT/ILL/829997/RASTRA NIRMAN/12005829997/NOIDA/10MB/P2M/3333', 'qos-profile': '10Mb', 'vlan-type': '1911', 'address': '14.98.77.69', 'netmask': '255.255.255.252', 'network': '14.98.77.68/30'}) ('Eth-Trunk1.1912', {'description': 'EXT/ILL/829765/SANGEET AUDIO INDIA PRIVATE LIMITED/12005829765/NOIDA/20MB/P2M/3333', 'qos-profile': '20Mb', 'vlan-type': '1912', 'address': '14.98.82.37', 'netmask': '255.255.255.252', 'network': '14.98.82.36/30'})
I want to print tuple values and dictionary values.

example

Eth-Trunk1.1908 EXT/ILL/830400/KAVERI INFORMATICS PRIVATE LIMITED/12005830400/NOIDA/2MB/P2M/3333 2Mb 1908 14.98.85.29 255.255.255.252 14.98.85.28/30
Larz60+ wrote Feb-13-2019, 10:12 AM:
You've been on the forum long enough to use proper BBcode tags.
more than one line of code, use python, not icode tags.
Quote
#2
This should do the trick.

for interface in result["interfaces"].items():
    print(interface[0], " ".join(interface[1].values()))
Quote
#3
Thanks, worked for me.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Being explicit about the items inside a tuple argument rudihammad 3 177 Dec-04-2019, 08:10 AM
Last Post: perfringo
  How to get first line of a tuple and the third item in its tuple. Need Help, Anybody? SukhmeetSingh 5 422 May-21-2019, 11:39 AM
Last Post: avorane
  return dict in tuple bb8 6 1,097 Feb-26-2018, 08:16 PM
Last Post: bb8

Forum Jump:


Users browsing this thread: 1 Guest(s)