Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- },
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {
- "collapsed": false
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "{'key1': 1,\n",
- " 'key2': '2',\n",
- " 'key3': [3, 3, 3],\n",
- " 'key4': (4, 4, 4),\n",
- " 'key5': 5,\n",
- " (0, 1): 6}"
- ]
- },
- "execution_count": 1,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# Create the dictionary\n",
- "\n",
- "Dict = {\"key1\": 1, \"key2\": \"2\", \"key3\": [3, 3, 3], \"key4\": (4, 4, 4), ('key5'): 5, (0, 1): 6}\n",
- "Dict"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "{'thriller': '1982',\n",
- " 'back in black': '1980',\n",
- " 'the dark side of the moon': '1973',\n",
- " 'the bodyguard': '1992',\n",
- " 'rumors': '1977'}"
- ]
- },
- "execution_count": 4,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "release_year_dict = {\"thriller\":\"1982\", \"back in black\":\"1980\",\n",
- " \"the dark side of the moon\":\"1973\",\"the bodyguard\":\"1992\",\n",
- " \"rumors\":\"1977\"}\n",
- "\n",
- "release_year_dict"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {
- "collapsed": false
- },
- "outputs": [
- {
- "data": {
- "text/plain": [
- "{'Thriller': '1982',\n",
- " 'Back in Black': '1980',\n",
- " 'The Dark Side of the Moon': '1973',\n",
- " 'The Bodyguard': '1992',\n",
- " 'Bat Out of Hell': '1977',\n",
- " 'Their Greatest Hits (1971-1975)': '1976',\n",
- " 'Saturday Night Fever': '1977',\n",
- " 'Rumours': '1977'}"
- ]
- },
- "execution_count": 5,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# Create a sample dictionary\n",
- "\n",
- "release_year_dict = {\"Thriller\": \"1982\", \"Back in Black\": \"1980\", \\\n",
- " \"The Dark Side of the Moon\": \"1973\", \"The Bodyguard\": \"1992\", \\\n",
- " \"Bat Out of Hell\": \"1977\", \"Their Greatest Hits (1971-1975)\": \"1976\", \\\n",
- " \"Saturday Night Fever\": \"1977\", \"Rumours\": \"1977\"}\n",
- "release_year_dict"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "'1982'"
- ]
- },
- "execution_count": 7,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "release_year_dict[\"Thriller\"]"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "'1977'"
- ]
- },
- "execution_count": 8,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "release_year_dict[\"Rumours\"]"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "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'])"
- ]
- },
- "execution_count": 9,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# get all the keys in a dict\n",
- "release_year_dict.keys()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 10,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "dict_values(['1982', '1980', '1973', '1992', '1977', '1976', '1977', '1977'])"
- ]
- },
- "execution_count": 10,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "release_year_dict.values()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 11,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "{'Thriller': '1982',\n",
- " 'Back in Black': '1980',\n",
- " 'The Dark Side of the Moon': '1973',\n",
- " 'The Bodyguard': '1992',\n",
- " 'Bat Out of Hell': '1977',\n",
- " 'Their Greatest Hits (1971-1975)': '1976',\n",
- " 'Saturday Night Fever': '1977',\n",
- " 'Rumours': '1977',\n",
- " 'Graduation': '1922'}"
- ]
- },
- "execution_count": 11,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# we can add with keys in a dict\n",
- "release_year_dict[\"Graduation\"]=\"1922\"\n",
- "release_year_dict"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 12,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "True"
- ]
- },
- "execution_count": 12,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "\"Rumours\" in release_year_dict"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 13,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "{'the bodyguard': '1992', 'saturday night fever': '1977'}"
- ]
- },
- "execution_count": 13,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "soundtrack_dic= {\"the bodyguard\":\"1992\", \"saturday night fever\":\"1977\"}\n",
- "soundtrack_dic"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 14,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "dict_values(['1992', '1977'])"
- ]
- },
- "execution_count": 14,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "soundtrack_dic.values()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 16,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "{'back in black': '50m', 'thriller': '50m', 'bodyguard': '65m'}"
- ]
- },
- "execution_count": 16,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "album_sales_dict ={\"back in black\":\"50m\",\"thriller\":\"50m\",\"bodyguard\":\"65m\"}\n",
- "album_sales_dict"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 17,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "'50m'"
- ]
- },
- "execution_count": 17,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "album_sales_dict[\"thriller\"]"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 18,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "dict_values(['50m', '50m', '65m'])"
- ]
- },
- "execution_count": 18,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "album_sales_dict.values()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.6.6"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
Add Comment
Please, Sign In to add comment