Get all values of dictionary in python by R4R Team

- values() is a python dictionary function which return all values from the dictionary.

Syntax-

dict.values()

Example

dictionary is d={1:'a',2:'b',3:'c'}


program-

d=dict()
print("Enter key 1")
n=input()
d.fromkeys(n)
print("Enter value of key 1")
d[n]=input()

print("Enter key 2")
n=input()
d.fromkeys(n)
print("Enter value of key 2")
d[n]=input()

print("Enter key 3")
n=input()
d.fromkeys(n)
print("Enter value of key 3")
d[n]=input()

print("Dictionary is ",d)
print("All values of dictionary is",d.values())
print("All values of dictionary is",*d.values())


output-

Enter key 1
1
Enter value of key 1
a
Enter key 2
2
Enter value of key 2
b
Enter key 3
3
Enter value of key 3
c
Dictionary is {'1': 'a', '2': 'b', '3': 'c'}
All values of dictionary is dict_values(['a', 'b', 'c'])
All values of dictionary is a b c


-In this program, we take a input of keys and their values and make a dictionary which is {'1': 'a', '2': 'b', '3': 'c'} then using d.values() we will get dict_values(['a', 'b', 'c']), then by *d.values() will give a b c.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!