Python Forum
Iterate a tuple with dict inside
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
Reply
#2
This should do the trick.

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  search in dict inside tuple steg 1 646 Mar-29-2023, 01:15 PM
Last Post: rob101
  Calculate the sum of the differences inside tuple PUP280 4 1,149 Aug-12-2022, 07:20 PM
Last Post: deanhystad
  What type of *data* is the name of a list/tuple/dict, etc? alloydog 9 4,253 Jan-30-2021, 07:11 AM
Last Post: alloydog
  code with no tuple gets : IndexError: tuple index out of range Aggam 4 2,725 Nov-04-2020, 11:26 AM
Last Post: Aggam
  Sort a dict in dict cherry_cherry 4 62,345 Apr-08-2020, 12:25 PM
Last Post: perfringo
  Being explicit about the items inside a tuple argument rudihammad 3 2,407 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 3,117 May-21-2019, 11:39 AM
Last Post: avorane
  return dict in tuple bb8 6 3,453 Feb-26-2018, 08:16 PM
Last Post: bb8

Forum Jump:

User Panel Messages

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