Skip to content

Commit 99d1798

Browse files
committed
Shorten amount of typing for dict example
1 parent 00bdc78 commit 99d1798

File tree

1 file changed

+49
-40
lines changed

1 file changed

+49
-40
lines changed

part-4.ipynb

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@
209209
"words = {\n",
210210
" 'gato': \"cat\",\n",
211211
" 'casa': \"house\",\n",
212-
" 'comio': \"ate\",\n",
213212
" 'esta': \"is\",\n",
214213
" 'en': \"in\",\n",
215214
" 'el': \"the\",\n",
@@ -247,6 +246,41 @@
247246
"metadata": {},
248247
"outputs": []
249248
},
249+
{
250+
"cell_type": "markdown",
251+
"metadata": {},
252+
"source": [
253+
"We can also reassign keys in our dictionary:"
254+
]
255+
},
256+
{
257+
"cell_type": "code",
258+
"collapsed": false,
259+
"input": [
260+
"words['gato'] = \"dog\"\n",
261+
"words['gato']"
262+
],
263+
"language": "python",
264+
"metadata": {},
265+
"outputs": []
266+
},
267+
{
268+
"cell_type": "markdown",
269+
"metadata": {},
270+
"source": [
271+
"Let's change that back so we don't confuse anyone:"
272+
]
273+
},
274+
{
275+
"cell_type": "code",
276+
"collapsed": false,
277+
"input": [
278+
"words['gato'] = \"cat\""
279+
],
280+
"language": "python",
281+
"metadata": {},
282+
"outputs": []
283+
},
250284
{
251285
"cell_type": "markdown",
252286
"metadata": {},
@@ -342,7 +376,6 @@
342376
"words = {\n",
343377
" 'gato': \"cat\",\n",
344378
" 'casa': \"house\",\n",
345-
" 'comio': \"ate\",\n",
346379
" 'esta': \"is\",\n",
347380
" 'en': \"in\",\n",
348381
" 'el': \"the\",\n",
@@ -364,7 +397,7 @@
364397
"cell_type": "code",
365398
"collapsed": false,
366399
"input": [
367-
"translate(\"el gato comio la casa\")"
400+
"translate(\"el gato esta en la casa\")"
368401
],
369402
"language": "python",
370403
"metadata": {},
@@ -374,41 +407,24 @@
374407
"cell_type": "markdown",
375408
"metadata": {},
376409
"source": [
377-
"Now let's make the words dictionary a Spain Spanish and Mexican Spanish to English dictionary. We'll start by adding a few keys and values."
410+
"Let's add another word to our dictionary:"
378411
]
379412
},
380413
{
381414
"cell_type": "code",
382415
"collapsed": false,
383416
"input": [
384-
"words['patatas'] = 'potatoes'\n",
385-
"words['papas'] = 'potatoes'\n",
386-
"words['zumo'] = 'juice'\n",
387-
"words['jugo'] = 'juice'\n",
388-
"words['y'] = 'and'\n",
389-
"words['comio'] = 'ate'\n",
390-
"words['bebi\u00f3'] = 'drank'\n",
391-
"words['las'] = 'the'\n",
392-
"words['galletas'] = 'cookies'\n",
393-
"words['papas-fritas'] = 'french fries'\n",
394-
"words['patatas-fritas'] = 'french fries'"
417+
"words['jugo'] = \"juice\""
395418
],
396419
"language": "python",
397420
"metadata": {},
398421
"outputs": []
399422
},
400-
{
401-
"cell_type": "markdown",
402-
"metadata": {},
403-
"source": [
404-
"Mexican Spanish to English translation:"
405-
]
406-
},
407423
{
408424
"cell_type": "code",
409425
"collapsed": false,
410426
"input": [
411-
"translate(\"el gato bebi\u00f3 el jugo y comio las papas\")"
427+
"translate(\"el jugo esta en la casa\")"
412428
],
413429
"language": "python",
414430
"metadata": {},
@@ -418,14 +434,15 @@
418434
"cell_type": "markdown",
419435
"metadata": {},
420436
"source": [
421-
"Spain Spanish to English translation:"
437+
"That's how we say juice in Mexican Spanish but what if we're traveling to Spain? Let's remove jugo from our dictionary and add zumo:"
422438
]
423439
},
424440
{
425441
"cell_type": "code",
426442
"collapsed": false,
427443
"input": [
428-
"translate(\"el gato bebi\u00f3 el zumo y comio las patatas\")"
444+
"del words['jugo']\n",
445+
"words['zumo'] = \"juice\""
429446
],
430447
"language": "python",
431448
"metadata": {},
@@ -435,39 +452,31 @@
435452
"cell_type": "markdown",
436453
"metadata": {},
437454
"source": [
438-
"To illustrate a few more dictionary concepts, let's convert our dictionary to Span Spanish to British English."
455+
"Let's try our Mexican Spanish sentence again. What should happen?"
439456
]
440457
},
441458
{
442459
"cell_type": "code",
443460
"collapsed": false,
444461
"input": [
445-
"#remove the Mexican Spanish key, values:\n",
446-
"del words['papas']\n",
447-
"del words['jugo']\n",
448-
"del words['papas-fritas']"
462+
"translate(\"el jugo esta en la casa\")"
449463
],
450464
"language": "python",
451465
"metadata": {},
452466
"outputs": []
453467
},
454468
{
455-
"cell_type": "code",
456-
"collapsed": false,
457-
"input": [
458-
"#change the values from English to British English:\n",
459-
"words['galletas'] = 'bisquits'\n",
460-
"words['patatas-fritas'] = 'chips'"
461-
],
462-
"language": "python",
469+
"cell_type": "markdown",
463470
"metadata": {},
464-
"outputs": []
471+
"source": [
472+
"Now let's try our Spanish Spanish sentence:"
473+
]
465474
},
466475
{
467476
"cell_type": "code",
468477
"collapsed": false,
469478
"input": [
470-
"translate(\"el gato bebi\u00f3 el zumo y comio las patatas-fritas y las galletas\")"
479+
"translate(\"el zumo esta en la casa\")"
471480
],
472481
"language": "python",
473482
"metadata": {},

0 commit comments

Comments
 (0)