#5, First Floor, 4th Street , Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

What are the methods of dictionary in python?
Description

To know about the most used methods of dictionary data type in python3.

Process

   This method is used to return the list with all dictionary keys without values.

Values():

   This method is used to return the list with all dictionary values only.

Len():

   It returns the count of key entities of the dictionary elements.

Type():

   This function returns the data type of the argument.

Copy():

   This function creates the shallow copy of the dictionary into other dictionary.

Sapmle Code

#sample dictionary

dic={‘age’:[25,26,25,23,

30,29,23,24,26,25],

‘rating’:[4,3.6,2.5,2.25,4.5,4.4,

3.9,3.5,3.7,3.2],
‘bonus’:[1300,1400,1250,1100,

1500,1450,1150,1100,1250,1200],

‘salary’:[2500,2600,2400,2200,3000,

2900,2300,2200,2450,2350],}

#empty dictionary

dic1={}

print(“****Dictionary keys*****\n”)

print (dic.keys())

print(“\n”)

print(“****Dictionary values*****\n”)

print(dic.values())

print(“\n”)

print(“*****Length of dictionary*****\n”)

print(len(dic))

print(“\n”)

print(“*****Data type*****\n”)

print(type(dic))

print(“\n”)

print(“*****Copy dic to dic1***\n”)

#copying the keys and values to another dictionary

dic1=dic.copy()

print(dic1.items())

Screenshots