Guest User

Untitled

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