Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInEmail this to someone
Create a Python dictionary and add key value pairs

In this short python tutorial we will take a look at how to create a dictionary in Python. Dictionaries are pretty fast, and they do not allow duplicate keys, so that can be handy if used right.

In this tutorial we will be creating the ‘cyberweapons’ dictionary, and we will be adding the threat level values and the descriptions of those threat levels to the dictionary.

The code to create a dictionary

cyberweapons = {}

Now we are going to add the keys ‘threatlevel1’, ‘threatlevel2’ and ‘threatlevel3’ to the dictionary, and each one of the keys will have its own description value:

cyberweapons[“threatlevel1”] = “This is threatlevel one. Immediate action needed.”  cyberweapons[“threatlevel2”] = “This is threatlevel 2.”  cyberweapons[“threatlevel3”] = “This is threatlevel 3.”

Now if you want to print one specific key value, you can do this by doing the following:

print(cyberweapons[“threatlevel1”])

Source

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInEmail this to someone
  • Learn more about eGRC Strategy, Products and Services click here
  • Learn more about Threat & Vulnerability Management Platforms click here
  • Learn more about Advanced End Point Protection click here
  • Learn more about NextGen Identity & Access Management Solutions click here