values()

The syntax of values() is as follows:

dict.values()

Let's consider the following example:

A1 = {'iron-man': 'Tony', 'CA': 'Steve', 'BW': 'Natasha', 'hulk': 'Bruce-Banner'} 

In the preceding dictionary, we want to get all the real names of our heroes:

 >>> A1 = {'iron-man': 'Tony', 'CA': 'Steve', 'BW': 'Natasha', 'hulk': 'Bruce-Banner'}
>>> A1.values()
['Tony', 'Steve', 'Natasha', 'Bruce-Banner']
>>>

Dictionary to another dictionary. Consider the following example: Sometimes, we need to add one dictionary to another dictionary. Consider the following example:

port1 = {22: "SSH", 23: "telnet", 80: "Http”}

We have another dictionary of ports, that is, port2 as shown:

port2 = {53 :"DNS", 443 : "https"} 

In order to update port1 with port2, we can take advantage of the update() method.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.227.9