Method 2 : Using values() method

we can use dictionary.values() to iterate over the tuples in a dictionary with for loop

Syntax:

for i in dictionary_name.values():
  for j in i:
      print(j)
  print(" ")

Example:

Python3




# Initializing a dictionary
myDict = {1: ("Apple", "Boy", "Cat"),
          2: ("Geeks", "For", "Geeks"),
          3: ("I", "Am", "Learning", "Python")}
 
# iterate over all tuples using
# values() method
for i in myDict.values():
    for j in i:
        print(j)
    print(" ")


Output:

Apple
Boy
Cat
 
Geeks
For
Geeks
 
I
Am
Learning
Python

Time complexity: O(n^2) where n is the number of tuples in the dictionary.

Auxiliary space: O(1)

Method 3 : Using items() and * operator 

Python3




# Initializing a dictionary
myDict = {1: ("Apple", "Boy", "Cat"),
          2: ("Geeks", "For", "Geeks"),
          3: ("I", "Am", "Learning", "Python")}
 
# iterate over all tuples using
# items() method
for key, tupleValues in myDict.items():
    print(*tupleValues)


Output

Apple Boy Cat
Geeks For Geeks
I Am Learning Python

Time Complexity: O(n), where n is the values in dictionary
Auxiliary Space: O(1), constant extra space required



Python – Iterate over Tuples in Dictionary

In this article, we will discuss how to Iterate over Tuples in Dictionary in Python. 

Similar Reads

Method 1: Using index

We can get the particular tuples by using an index:...

Method 2 : Using values() method

...

Contact Us