Python Forum
Iterate a tuple with dict inside - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Iterate a tuple with dict inside (/thread-16067.html)



Iterate a tuple with dict inside - anna - Feb-13-2019

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


RE: Iterate a tuple with dict inside - stullis - Feb-13-2019

This should do the trick.

for interface in result["interfaces"].items():
    print(interface[0], " ".join(interface[1].values()))



RE: Iterate a tuple with dict inside - anna - Feb-13-2019

Thanks, worked for me.