I tried something like this :
for key in dict_of_ims:
for element in key:
print(element)
it just gave the keys letter by letter
I tried something like this :
for key in dict_of_ims:
for element in key:
print(element)
it just gave the keys letter by letter
Use values
:
print(dict_of_ims.values())
Or to unpack the values:
for val in dict_of_ims.values():
for item in val:
print(item)
If you want to print all the values of a list which is value for each key in a dictionary:
for key, value in dict1.items():
for ele in value:
print(ele)
Example:
dict1 = {'milk': ['gallons', 5, 10, 50], 'name': ['hari']}
Output:
gallons
5
10
50
hari
for key in dict_of_ims:
print(dict_of_ims[key])
In dict values method is there
print(dict_of_ims.values())
will return list of values
print(dict_of_ims.keys())
will return list of keys
Based on your comments on other answers, your dictionary will look something like this:
d = {'a': [1, 2, 3, 4], 'b': [7, 8, 9]}
Now you can use chain
from itertools
to get your desired output:
from itertools import chain
values = list(chain.from_iterable(d.values()))
print(values)
Output:
[1, 2, 3, 4, 7, 8, 9]
You can further, format it based on your requirement:
>>> print(" ".join(values))
1 2 3 4 7 8 9
>>> print("\n".join(values))
1
2
3
4
7
8
9