|
22 | 22 | { |
23 | 23 | "cell_type": "code", |
24 | 24 | "execution_count": null, |
25 | | - "metadata": { |
26 | | - "collapsed": false |
27 | | - }, |
| 25 | + "metadata": {}, |
28 | 26 | "outputs": [], |
29 | 27 | "source": [ |
30 | 28 | "fruit_season = {\n", |
|
34 | 32 | " 'grape' : 'August'\n", |
35 | 33 | "} \n", |
36 | 34 | "\n", |
37 | | - "print type(fruit_season)\n", |
38 | | - "print fruit_season" |
| 35 | + "print(type(fruit_season))\n", |
| 36 | + "print(fruit_season)" |
39 | 37 | ] |
40 | 38 | }, |
41 | 39 | { |
|
50 | 48 | { |
51 | 49 | "cell_type": "code", |
52 | 50 | "execution_count": null, |
53 | | - "metadata": { |
54 | | - "collapsed": false |
55 | | - }, |
| 51 | + "metadata": {}, |
56 | 52 | "outputs": [], |
57 | 53 | "source": [ |
58 | 54 | "raspberry_season = fruit_season['raspberry']\n", |
59 | | - "print raspberry_season" |
| 55 | + "print(raspberry_season)" |
60 | 56 | ] |
61 | 57 | }, |
62 | 58 | { |
|
69 | 65 | { |
70 | 66 | "cell_type": "code", |
71 | 67 | "execution_count": null, |
72 | | - "metadata": { |
73 | | - "collapsed": false |
74 | | - }, |
| 68 | + "metadata": {}, |
75 | 69 | "outputs": [], |
76 | 70 | "source": [ |
77 | | - "print fruit_season['mangos']" |
| 71 | + "print(fruit_season['mangos'])" |
78 | 72 | ] |
79 | 73 | }, |
80 | 74 | { |
|
89 | 83 | { |
90 | 84 | "cell_type": "code", |
91 | 85 | "execution_count": null, |
92 | | - "metadata": { |
93 | | - "collapsed": false |
94 | | - }, |
| 86 | + "metadata": {}, |
95 | 87 | "outputs": [], |
96 | 88 | "source": [ |
97 | 89 | "fruit_season['strawberry'] = 'May'\n", |
98 | | - "print fruit_season" |
| 90 | + "print(fruit_season)" |
99 | 91 | ] |
100 | 92 | }, |
101 | 93 | { |
|
110 | 102 | { |
111 | 103 | "cell_type": "code", |
112 | 104 | "execution_count": null, |
113 | | - "metadata": { |
114 | | - "collapsed": false |
115 | | - }, |
| 105 | + "metadata": {}, |
116 | 106 | "outputs": [], |
117 | 107 | "source": [ |
118 | 108 | "del fruit_season['strawberry']\n", |
119 | | - "print fruit_season" |
| 109 | + "print(fruit_season)" |
120 | 110 | ] |
121 | 111 | }, |
122 | 112 | { |
|
132 | 122 | { |
133 | 123 | "cell_type": "code", |
134 | 124 | "execution_count": null, |
135 | | - "metadata": { |
136 | | - "collapsed": false |
137 | | - }, |
| 125 | + "metadata": {}, |
138 | 126 | "outputs": [], |
139 | 127 | "source": [ |
140 | 128 | "duplicate_fruit_season = {\n", |
141 | 129 | " 'raspberry': 'May',\n", |
142 | 130 | " 'raspberry': 'June',\n", |
143 | 131 | "} \n", |
144 | | - "print duplicate_fruit_season" |
| 132 | + "print(duplicate_fruit_season)" |
145 | 133 | ] |
146 | 134 | }, |
147 | 135 | { |
148 | 136 | "cell_type": "code", |
149 | 137 | "execution_count": null, |
150 | | - "metadata": { |
151 | | - "collapsed": false |
152 | | - }, |
| 138 | + "metadata": {}, |
153 | 139 | "outputs": [], |
154 | 140 | "source": [ |
155 | 141 | "mutable_key = {\n", |
|
182 | 168 | { |
183 | 169 | "cell_type": "code", |
184 | 170 | "execution_count": null, |
185 | | - "metadata": { |
186 | | - "collapsed": false |
187 | | - }, |
| 171 | + "metadata": {}, |
188 | 172 | "outputs": [], |
189 | 173 | "source": [] |
190 | 174 | }, |
|
202 | 186 | { |
203 | 187 | "cell_type": "code", |
204 | 188 | "execution_count": null, |
205 | | - "metadata": { |
206 | | - "collapsed": false |
207 | | - }, |
| 189 | + "metadata": {}, |
208 | 190 | "outputs": [], |
209 | 191 | "source": [ |
210 | | - "print 'raspberry' in fruit_season\n", |
211 | | - "print 'mangos' in fruit_season" |
| 192 | + "print('raspberry' in fruit_season)\n", |
| 193 | + "print('mangos' in fruit_season)" |
212 | 194 | ] |
213 | 195 | }, |
214 | 196 | { |
|
221 | 203 | { |
222 | 204 | "cell_type": "code", |
223 | 205 | "execution_count": null, |
224 | | - "metadata": { |
225 | | - "collapsed": false |
226 | | - }, |
| 206 | + "metadata": {}, |
227 | 207 | "outputs": [], |
228 | 208 | "source": [ |
229 | 209 | "if 'pineapple' in fruit_season:\n", |
230 | | - " print 'Lets eat tropical fruit'\n", |
| 210 | + " print('Lets eat tropical fruit')\n", |
231 | 211 | "else:\n", |
232 | | - " print \"Temperate fruit it is.\"" |
| 212 | + " print(\"Temperate fruit it is.\")" |
233 | 213 | ] |
234 | 214 | }, |
235 | 215 | { |
|
264 | 244 | { |
265 | 245 | "cell_type": "code", |
266 | 246 | "execution_count": null, |
267 | | - "metadata": { |
268 | | - "collapsed": false |
269 | | - }, |
| 247 | + "metadata": {}, |
270 | 248 | "outputs": [], |
271 | 249 | "source": [ |
272 | 250 | "for fruit in fruit_season:\n", |
273 | | - " print \"{0} is best in {1} (at least in Virginia)\".format(fruit.title(), fruit_season[fruit])" |
| 251 | + " print(\"{0} is best in {1} (at least in Virginia)\".format(fruit.title(), fruit_season[fruit]))" |
274 | 252 | ] |
275 | 253 | }, |
276 | 254 | { |
|
287 | 265 | { |
288 | 266 | "cell_type": "code", |
289 | 267 | "execution_count": null, |
290 | | - "metadata": { |
291 | | - "collapsed": false |
292 | | - }, |
| 268 | + "metadata": {}, |
293 | 269 | "outputs": [], |
294 | 270 | "source": [ |
295 | | - "print fruit_season.keys()\n", |
296 | | - "print fruit_season.values()\n", |
297 | | - "print fruit_season.items()" |
| 271 | + "print(fruit_season.keys())\n", |
| 272 | + "print(fruit_season.values())\n", |
| 273 | + "print(fruit_season.items())" |
298 | 274 | ] |
299 | 275 | }, |
300 | 276 | { |
301 | 277 | "cell_type": "code", |
302 | 278 | "execution_count": null, |
303 | | - "metadata": { |
304 | | - "collapsed": false |
305 | | - }, |
| 279 | + "metadata": {}, |
306 | 280 | "outputs": [], |
307 | 281 | "source": [ |
308 | 282 | "for key, value in fruit_season.items():\n", |
309 | | - " print \"In {0} eat a {1}\".format(value, key)" |
| 283 | + " print(\"In {0} eat a {1}\".format(value, key))" |
310 | 284 | ] |
311 | 285 | }, |
312 | 286 | { |
313 | 287 | "cell_type": "code", |
314 | 288 | "execution_count": null, |
315 | | - "metadata": { |
316 | | - "collapsed": false |
317 | | - }, |
| 289 | + "metadata": {}, |
318 | 290 | "outputs": [], |
319 | 291 | "source": [ |
320 | | - "print sorted(fruit_season.keys())" |
| 292 | + "print(sorted(fruit_season.keys()))" |
321 | 293 | ] |
322 | 294 | }, |
323 | 295 | { |
|
331 | 303 | { |
332 | 304 | "cell_type": "code", |
333 | 305 | "execution_count": null, |
334 | | - "metadata": { |
335 | | - "collapsed": false |
336 | | - }, |
| 306 | + "metadata": {}, |
337 | 307 | "outputs": [], |
338 | 308 | "source": [] |
339 | 309 | }, |
|
352 | 322 | { |
353 | 323 | "cell_type": "code", |
354 | 324 | "execution_count": null, |
355 | | - "metadata": { |
356 | | - "collapsed": false |
357 | | - }, |
| 325 | + "metadata": {}, |
358 | 326 | "outputs": [], |
359 | 327 | "source": [ |
360 | 328 | "my_complicated_dictionary = {\n", |
|
368 | 336 | " },\n", |
369 | 337 | " 9: [3, 3]\n", |
370 | 338 | "}\n", |
371 | | - "print my_complicated_dictionary" |
| 339 | + "print(my_complicated_dictionary)" |
372 | 340 | ] |
373 | 341 | }, |
374 | 342 | { |
|
381 | 349 | { |
382 | 350 | "cell_type": "code", |
383 | 351 | "execution_count": null, |
384 | | - "metadata": { |
385 | | - "collapsed": false |
386 | | - }, |
| 352 | + "metadata": {}, |
387 | 353 | "outputs": [], |
388 | 354 | "source": [ |
389 | 355 | "true_fruit_season = {\n", |
|
393 | 359 | " 'grape': ['August', 'September', 'October']\n", |
394 | 360 | "} \n", |
395 | 361 | "\n", |
396 | | - "print true_fruit_season" |
| 362 | + "print(true_fruit_season)" |
397 | 363 | ] |
398 | 364 | }, |
399 | 365 | { |
400 | 366 | "cell_type": "code", |
401 | 367 | "execution_count": null, |
402 | | - "metadata": { |
403 | | - "collapsed": false |
404 | | - }, |
| 368 | + "metadata": {}, |
405 | 369 | "outputs": [], |
406 | 370 | "source": [ |
407 | 371 | "months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']\n", |
408 | 372 | "\n", |
409 | 373 | "for month in months:\n", |
410 | | - " print 'It is {0}'.format(month)\n", |
| 374 | + " print('It is {0}'.format(month))\n", |
411 | 375 | " for fruit, season in true_fruit_season.items():\n", |
412 | 376 | " if month in season:\n", |
413 | | - " print \"\\tEat {0}\".format(fruit)" |
| 377 | + " print(\"\\tEat {0}\".format(fruit))" |
414 | 378 | ] |
415 | 379 | }, |
416 | 380 | { |
|
424 | 388 | { |
425 | 389 | "cell_type": "code", |
426 | 390 | "execution_count": null, |
427 | | - "metadata": { |
428 | | - "collapsed": false |
429 | | - }, |
| 391 | + "metadata": {}, |
430 | 392 | "outputs": [], |
431 | 393 | "source": [] |
432 | 394 | }, |
|
471 | 433 | { |
472 | 434 | "cell_type": "code", |
473 | 435 | "execution_count": null, |
474 | | - "metadata": { |
475 | | - "collapsed": false |
476 | | - }, |
| 436 | + "metadata": {}, |
477 | 437 | "outputs": [], |
478 | 438 | "source": [ |
479 | 439 | "# If you have a list of adjectives\n", |
|
488 | 448 | " first_char = i[0]\n", |
489 | 449 | " if first_char in my_dict:\n", |
490 | 450 | " my_dict[first_char].append(i)\n", |
491 | | - "print my_dict" |
| 451 | + "print(my_dict)" |
492 | 452 | ] |
493 | 453 | }, |
494 | 454 | { |
495 | 455 | "cell_type": "code", |
496 | 456 | "execution_count": null, |
497 | | - "metadata": { |
498 | | - "collapsed": false |
499 | | - }, |
| 457 | + "metadata": {}, |
500 | 458 | "outputs": [], |
501 | 459 | "source": [ |
502 | 460 | "# Generating from a file\n", |
|
513 | 471 | " if first_char in my_dict:\n", |
514 | 472 | " my_dict[first_char].append(word)\n", |
515 | 473 | " \n", |
516 | | - "print my_dict['A']" |
| 474 | + "print(my_dict['A'])" |
517 | 475 | ] |
518 | 476 | }, |
519 | 477 | { |
|
528 | 486 | ], |
529 | 487 | "metadata": { |
530 | 488 | "kernelspec": { |
531 | | - "display_name": "Python 2", |
| 489 | + "display_name": "Python 3", |
532 | 490 | "language": "python", |
533 | | - "name": "python2" |
| 491 | + "name": "python3" |
534 | 492 | }, |
535 | 493 | "language_info": { |
536 | 494 | "codemirror_mode": { |
537 | 495 | "name": "ipython", |
538 | | - "version": 2 |
| 496 | + "version": 3 |
539 | 497 | }, |
540 | 498 | "file_extension": ".py", |
541 | 499 | "mimetype": "text/x-python", |
542 | 500 | "name": "python", |
543 | 501 | "nbconvert_exporter": "python", |
544 | | - "pygments_lexer": "ipython2", |
545 | | - "version": "2.7.11" |
| 502 | + "pygments_lexer": "ipython3", |
| 503 | + "version": "3.6.1" |
546 | 504 | } |
547 | 505 | }, |
548 | 506 | "nbformat": 4, |
549 | | - "nbformat_minor": 0 |
| 507 | + "nbformat_minor": 1 |
550 | 508 | } |
0 commit comments