SHARE
TWEET

Untitled

a guest Sep 17th, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {
  2.  "cells": [
  3.   {
  4.    "cell_type": "code",
  5.    "execution_count": 1,
  6.    "metadata": {},
  7.    "outputs": [
  8.     {
  9.      "data": {
  10.       "text/plain": [
  11.        "{'key1': 1,\n",
  12.        " 'key2': '2',\n",
  13.        " 'key3': [3, 3, 3],\n",
  14.        " 'key4': (4, 4, 4),\n",
  15.        " 'key5': 5,\n",
  16.        " (0, 1): 6}"
  17.       ]
  18.      },
  19.      "execution_count": 1,
  20.      "metadata": {},
  21.      "output_type": "execute_result"
  22.     }
  23.    ],
  24.    "source": [
  25.     "# Create the dictionary\n",
  26.     "\n",
  27.     "Dict = {\"key1\": 1, \"key2\": \"2\", \"key3\": [3, 3, 3], \"key4\": (4, 4, 4), ('key5'): 5, (0, 1): 6}\n",
  28.     "Dict"
  29.    ]
  30.   },
  31.   {
  32.    "cell_type": "code",
  33.    "execution_count": 3,
  34.    "metadata": {},
  35.    "outputs": [
  36.     {
  37.      "data": {
  38.       "text/plain": [
  39.        "1"
  40.       ]
  41.      },
  42.      "execution_count": 3,
  43.      "metadata": {},
  44.      "output_type": "execute_result"
  45.     }
  46.    ],
  47.    "source": [
  48.     "Dict[\"key1\"]"
  49.    ]
  50.   },
  51.   {
  52.    "cell_type": "code",
  53.    "execution_count": 4,
  54.    "metadata": {},
  55.    "outputs": [
  56.     {
  57.      "data": {
  58.       "text/plain": [
  59.        "6"
  60.       ]
  61.      },
  62.      "execution_count": 4,
  63.      "metadata": {},
  64.      "output_type": "execute_result"
  65.     }
  66.    ],
  67.    "source": [
  68.     "Dict[(0,1)]"
  69.    ]
  70.   },
  71.   {
  72.    "cell_type": "code",
  73.    "execution_count": 5,
  74.    "metadata": {},
  75.    "outputs": [
  76.     {
  77.      "data": {
  78.       "text/plain": [
  79.        "{'Thriller': '1982',\n",
  80.        " 'Back in Black': '1980',\n",
  81.        " 'The Dark Side of the Moon': '1973',\n",
  82.        " 'The Bodyguard': '1992',\n",
  83.        " 'Bat Out of Hell': '1977',\n",
  84.        " 'Their Greatest Hits (1971-1975)': '1976',\n",
  85.        " 'Saturday Night Fever': '1977',\n",
  86.        " 'Rumours': '1977'}"
  87.       ]
  88.      },
  89.      "execution_count": 5,
  90.      "metadata": {},
  91.      "output_type": "execute_result"
  92.     }
  93.    ],
  94.    "source": [
  95.     "# Create a sample dictionary\n",
  96.     "\n",
  97.     "release_year_dict = {\"Thriller\": \"1982\", \"Back in Black\": \"1980\", \\\n",
  98.     "                    \"The Dark Side of the Moon\": \"1973\", \"The Bodyguard\": \"1992\", \\\n",
  99.     "                    \"Bat Out of Hell\": \"1977\", \"Their Greatest Hits (1971-1975)\": \"1976\", \\\n",
  100.     "                    \"Saturday Night Fever\": \"1977\", \"Rumours\": \"1977\"}\n",
  101.     "release_year_dict"
  102.    ]
  103.   },
  104.   {
  105.    "cell_type": "code",
  106.    "execution_count": 6,
  107.    "metadata": {},
  108.    "outputs": [
  109.     {
  110.      "data": {
  111.       "text/plain": [
  112.        "'1982'"
  113.       ]
  114.      },
  115.      "execution_count": 6,
  116.      "metadata": {},
  117.      "output_type": "execute_result"
  118.     }
  119.    ],
  120.    "source": [
  121.     "# Get value by keys\n",
  122.     "\n",
  123.     "release_year_dict['Thriller'] "
  124.    ]
  125.   },
  126.   {
  127.    "cell_type": "code",
  128.    "execution_count": 7,
  129.    "metadata": {},
  130.    "outputs": [
  131.     {
  132.      "data": {
  133.       "text/plain": [
  134.        "'1992'"
  135.       ]
  136.      },
  137.      "execution_count": 7,
  138.      "metadata": {},
  139.      "output_type": "execute_result"
  140.     }
  141.    ],
  142.    "source": [
  143.     "# Get value by key\n",
  144.     "\n",
  145.     "release_year_dict['The Bodyguard'] "
  146.    ]
  147.   },
  148.   {
  149.    "cell_type": "code",
  150.    "execution_count": 8,
  151.    "metadata": {},
  152.    "outputs": [
  153.     {
  154.      "data": {
  155.       "text/plain": [
  156.        "dict_keys(['Thriller', 'Back in Black', 'The Dark Side of the Moon', 'The Bodyguard', 'Bat Out of Hell', 'Their Greatest Hits (1971-1975)', 'Saturday Night Fever', 'Rumours'])"
  157.       ]
  158.      },
  159.      "execution_count": 8,
  160.      "metadata": {},
  161.      "output_type": "execute_result"
  162.     }
  163.    ],
  164.    "source": [
  165.     "# Get all the keys in dictionary\n",
  166.     "\n",
  167.     "release_year_dict.keys() "
  168.    ]
  169.   },
  170.   {
  171.    "cell_type": "code",
  172.    "execution_count": 9,
  173.    "metadata": {},
  174.    "outputs": [
  175.     {
  176.      "data": {
  177.       "text/plain": [
  178.        "dict_values(['1982', '1980', '1973', '1992', '1977', '1976', '1977', '1977'])"
  179.       ]
  180.      },
  181.      "execution_count": 9,
  182.      "metadata": {},
  183.      "output_type": "execute_result"
  184.     }
  185.    ],
  186.    "source": [
  187.     "release_year_dict.values()"
  188.    ]
  189.   },
  190.   {
  191.    "cell_type": "code",
  192.    "execution_count": 10,
  193.    "metadata": {},
  194.    "outputs": [
  195.     {
  196.      "data": {
  197.       "text/plain": [
  198.        "{'Thriller': '1982',\n",
  199.        " 'Back in Black': '1980',\n",
  200.        " 'The Dark Side of the Moon': '1973',\n",
  201.        " 'The Bodyguard': '1992',\n",
  202.        " 'Bat Out of Hell': '1977',\n",
  203.        " 'Their Greatest Hits (1971-1975)': '1976',\n",
  204.        " 'Saturday Night Fever': '1977',\n",
  205.        " 'Rumours': '1977',\n",
  206.        " 'Graduation': '2007'}"
  207.       ]
  208.      },
  209.      "execution_count": 10,
  210.      "metadata": {},
  211.      "output_type": "execute_result"
  212.     }
  213.    ],
  214.    "source": [
  215.     "#Add an entry to the dictionary\n",
  216.     "release_year_dict['Graduation']='2007'\n",
  217.     "release_year_dict"
  218.    ]
  219.   },
  220.   {
  221.    "cell_type": "code",
  222.    "execution_count": 11,
  223.    "metadata": {},
  224.    "outputs": [
  225.     {
  226.      "data": {
  227.       "text/plain": [
  228.        "{'Thriller': '1982',\n",
  229.        " 'Back in Black': '1980',\n",
  230.        " 'The Dark Side of the Moon': '1973',\n",
  231.        " 'The Bodyguard': '1992',\n",
  232.        " 'Bat Out of Hell': '1977',\n",
  233.        " 'Their Greatest Hits (1971-1975)': '1976',\n",
  234.        " 'Saturday Night Fever': '1977',\n",
  235.        " 'Rumours': '1977'}"
  236.       ]
  237.      },
  238.      "execution_count": 11,
  239.      "metadata": {},
  240.      "output_type": "execute_result"
  241.     }
  242.    ],
  243.    "source": [
  244.     "# Delete entries by key\n",
  245.     "del(release_year_dict['Graduation'])\n",
  246.     "release_year_dict"
  247.    ]
  248.   },
  249.   {
  250.    "cell_type": "code",
  251.    "execution_count": 12,
  252.    "metadata": {},
  253.    "outputs": [
  254.     {
  255.      "data": {
  256.       "text/plain": [
  257.        "True"
  258.       ]
  259.      },
  260.      "execution_count": 12,
  261.      "metadata": {},
  262.      "output_type": "execute_result"
  263.     }
  264.    ],
  265.    "source": [
  266.     "#Verify if key is in disctionary\n",
  267.     "'Rumours' in release_year_dict"
  268.    ]
  269.   },
  270.   {
  271.    "cell_type": "code",
  272.    "execution_count": 13,
  273.    "metadata": {},
  274.    "outputs": [
  275.     {
  276.      "data": {
  277.       "text/plain": [
  278.        "{'The Bodyguard': '1992', 'Saturday Night Fever': '1977'}"
  279.       ]
  280.      },
  281.      "execution_count": 13,
  282.      "metadata": {},
  283.      "output_type": "execute_result"
  284.     }
  285.    ],
  286.    "source": [
  287.     "soundtrack_dic = {\"The Bodyguard\":\"1992\", \"Saturday Night Fever\":\"1977\"}\n",
  288.     "soundtrack_dic"
  289.    ]
  290.   },
  291.   {
  292.    "cell_type": "code",
  293.    "execution_count": 14,
  294.    "metadata": {},
  295.    "outputs": [
  296.     {
  297.      "data": {
  298.       "text/plain": [
  299.        "dict_keys(['The Bodyguard', 'Saturday Night Fever'])"
  300.       ]
  301.      },
  302.      "execution_count": 14,
  303.      "metadata": {},
  304.      "output_type": "execute_result"
  305.     }
  306.    ],
  307.    "source": [
  308.     "soundtrack_dic.keys()"
  309.    ]
  310.   },
  311.   {
  312.    "cell_type": "code",
  313.    "execution_count": 15,
  314.    "metadata": {},
  315.    "outputs": [
  316.     {
  317.      "data": {
  318.       "text/plain": [
  319.        "dict_values(['1992', '1977'])"
  320.       ]
  321.      },
  322.      "execution_count": 15,
  323.      "metadata": {},
  324.      "output_type": "execute_result"
  325.     }
  326.    ],
  327.    "source": [
  328.     "soundtrack_dic.values()"
  329.    ]
  330.   },
  331.   {
  332.    "cell_type": "code",
  333.    "execution_count": 17,
  334.    "metadata": {},
  335.    "outputs": [
  336.     {
  337.      "data": {
  338.       "text/plain": [
  339.        "{'Back in Black': 50, 'The Bodyguard': 50, 'Thriller': 65}"
  340.       ]
  341.      },
  342.      "execution_count": 17,
  343.      "metadata": {},
  344.      "output_type": "execute_result"
  345.     }
  346.    ],
  347.    "source": [
  348.     "album_sales_dict={\"Back in Black\":50,\"The Bodyguard\":50,\"Thriller\":65}\n",
  349.     "album_sales_dict"
  350.    ]
  351.   },
  352.   {
  353.    "cell_type": "code",
  354.    "execution_count": null,
  355.    "metadata": {},
  356.    "outputs": [],
  357.    "source": []
  358.   }
  359.  ],
  360.  "metadata": {
  361.   "kernelspec": {
  362.    "display_name": "Python",
  363.    "language": "python",
  364.    "name": "conda-env-python-py"
  365.   },
  366.   "language_info": {
  367.    "codemirror_mode": {
  368.     "name": "ipython",
  369.     "version": 3
  370.    },
  371.    "file_extension": ".py",
  372.    "mimetype": "text/x-python",
  373.    "name": "python",
  374.    "nbconvert_exporter": "python",
  375.    "pygments_lexer": "ipython3",
  376.    "version": "3.6.7"
  377.   }
  378.  },
  379.  "nbformat": 4,
  380.  "nbformat_minor": 4
  381. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top