ISO 9001:2015 Certified Company

Sukrala IT Services Pvt. Ltd.,
SCO 23-24-25, Level 3rd,
SEC 34-A, Chandigarh.
Phone: 99-88-74-1983, 0172-503-1983

Dictionary in Python
  • 0

Dictionary in Python

Category : Blog

Dictionary is another example of a data structure. The dictionary is used to draw and connect items that are necessary to get them. The Dictionary in Python is like a dictionary in the real world. Python Dictionary is defined by the two elements, the key and the value.

  • The keys are one element
  • Values may be a list or list of lists, such as lists and numbers.

Now we are discussing about Python Dictionary Key and Methods:-

 

  • Properties of Dictionary Keys:-

 

  • One key is more than one entry allowed (excluding duplicate keys)
  • The values in the dictionary can be any type. Keys must be immutable as numbers, characters, or characters.
  • Dictionary buttons are sensitive to user sensitivity. Similarly, Python’s unique but unique approach is treated with different keys.

 

  • Python Dictionary Methods

  • Copy of dictionary

 

You can write a dictionary for a dictionary. For example, here we have duplicated the dictionaries by the new name “Boys” and “Girls.”

Example:-

Dict = {‘Tim’: 18,’Charlie’:12,’Tiffany’:22,’Robert’:25}   

Boys = {‘Tim’: 18,’Charlie’:12,’Robert’:25}

Girls = {‘Tiffany’:22}   

studentX=Boys.copy()

studentY=Girls.copy()

print studentX

print studentY

 

 

  • Refine dictionary in Python:- You can enter a dictionary by entering a new entry or keyword combination by deleting the current entry or by deleting an existing inputor. In this example, we will add to our dictionary “Sarah”.

 

Example:-

Dict = {‘Tim’: 18,’Charlie’:12,’Tiffany’:22,’Robert’:25}   

Dict.update({“Sarah”:9})

print Dict

 

 

  • Delete dictionaries in Python:- The Python Dictionary gives you the freedom to remove any element from the dictionary list. If you do not want Charlie’s name in the list, you can remove the key by following:

 

Example:-

Dict = {‘Tim’: 18,’Charlie’:12,’Tiffany’:22,’Robert’:25}   

del Dict [‘Charlie’]

print Dict

 

 

  • Dictionary () Method:- These () methods are returned from the dictionary by the tuple pair (Keys, Value).

 

Example:-

Dict = {‘Tim’: 18,’Charlie’:12,’Tiffany’:22,’Robert’:25}   

print “Students Name: %s” % Dict.items()

  • We use the Dict’s code () method.
  • Returns the list of items in the dictionary (keys and values) when running the code

 

  • Distinguish of the dictionary:- In the dictionary, you can sort the elements. For example, if we want to print the name of the element in the dictionary in print format, we must use the domain. This will properly classify each element of the dictionary.

 

Example:-

Dict = {‘Tim’: 18,’Charlie’:12,’Tiffany’:22,’Robert’:25}

Boys = {‘Tim’: 18,’Charlie’:12,’Robert’:25}

Girls = {‘Tiffany’:22}

Students = Dict.keys()

Students.sort()

for S in Students:

     print”:”.join((S,str(Dict[S])))

  • We have the “Dict” variables in the dictionary.
  • Then we use the Students.sort code to classify elements within the dictionary
  • However, for each element to be subtracted for the dictionary, run the domain as declared S
  • Now, we run the code from the dictionary to run the code, which will print the line and value in the order.

 

  • Python features built-in dictionary:-

 

  • Dictionaries Lén () Method:- The len () function gives a pair of dictionaries.

Example:-

Dict = {‘Tim’: 18,’Charlie’:12,’Tiffany’:22,’Robert’:25}   

print “Length : %d” % len (Dict)

When performing the function of Len (Dict) we have four elements in our dictionary and therefore output to “4”

 

 

  • Variable type

 

Python does not need to specify a memory space; This is done automatically. Use the equals “=” equal to the character. The code defining the variable type is “% type (Dict)”.

Example:-

Dict = {‘Tim’: 18,’Charlie’:12,’Tiffany’:22,’Robert’:25}   

print “variable Type: %s” %type (Dict)

 

 

  • Python List cmp () Method:- The comparison method is used in Python to calculate the key and the key value for cmp (). If two dictionaries return the same method, 1 is dic1> dict2 and 1 is dict1 <dict2.

 

Example:-

Boys = {‘Tim’: 18,’Charlie’:12,’Robert’:25}

Girls = {‘Tiffany’:22}   

print cmp(Girls, Boys)

 

Read More AT – Future Scope Of Python Languages

  • We have the names of “Boys” and “Girls”.
  • “Cmp (Girls and Boys)” presents you the first one. 1. In case we have “Girls” as the first one, we will look at dictionary 1 and boys as a dictionary 2.
  • If print is printed when -1, print 1 indicates that dictionary 1 is less than dictionary 2.

Conclusion:-

Dictionary in Python language is a data structure used to store information related to other sites. Python Dictionary is defined by the two elements, the key and the value. Dictionaries do not store their information in any particular order, so your information may not get back to the order you entered.

 

  • The keys are one element
  • Values ​​may be a list or list of lists, such as lists and numbers.
  • One key is more than one entry allowed (excluding duplicate keys)
  • The values ​​in the dictionary can be any type. Keys must be immutable as numbers, characters, or characters.
  • Dictionary buttons are sensitive to user sensitivity. Similarly, Python’s unique but unique approach is treated with different keys.

CBitss Technologies provides Leading Python training  in Chandigarh. We have a team of experienced professionals with more than 10 years of experience in Python and other related technologies.  More Details Visit Our website ..


Leave a Reply

Facebook Likes

error: Content is protected !!