|
28 | 28 | " \"Panos\": \"212-998-0803\",\n", |
29 | 29 | " \"Maria\": \"656-233-5555\",\n", |
30 | 30 | " \"John\": \"693-232-5776\",\n", |
31 | | - " \"Jake\": \"415-794-3423\"\n", |
| 31 | + " \"Jake\": \"415-794-3423\",\n", |
32 | 32 | "}" |
33 | 33 | ] |
34 | 34 | }, |
|
80 | 80 | " \"Panos\": [\"212-998-0803\", \"917-888-4455\"],\n", |
81 | 81 | " \"Maria\": [\"656-233-5555\"],\n", |
82 | 82 | " \"John\": [\"693-232-5776\"],\n", |
83 | | - " \"Jake\": [\"415-794-3423\"]\n", |
| 83 | + " \"Jake\": [\"415-794-3423\"],\n", |
84 | 84 | "}" |
85 | 85 | ] |
86 | 86 | }, |
|
134 | 134 | "outputs": [], |
135 | 135 | "source": [ |
136 | 136 | "phones = {\n", |
137 | | - " \"Panos\": {\n", |
138 | | - " \"Work\": \"212-998-0803\",\n", |
139 | | - " \"Cell\": \"917-888-4455\"\n", |
140 | | - " },\n", |
141 | | - " \"Maria\": {\n", |
142 | | - " \"Work\": \"656-233-5555\"\n", |
143 | | - " },\n", |
144 | | - " \"John\": {\n", |
145 | | - " \"Cell\": \"693-232-5776\"\n", |
146 | | - " },\n", |
147 | | - " \"Jake\": {\n", |
148 | | - " \"Home\": \"415-794-3423\"\n", |
149 | | - " }\n", |
| 137 | + " \"Panos\": {\"Work\": \"212-998-0803\", \"Cell\": \"917-888-4455\"},\n", |
| 138 | + " \"Maria\": {\"Work\": \"656-233-5555\"},\n", |
| 139 | + " \"John\": {\"Cell\": \"693-232-5776\"},\n", |
| 140 | + " \"Jake\": {\"Home\": \"415-794-3423\"},\n", |
150 | 141 | "}" |
151 | 142 | ] |
152 | 143 | }, |
|
181 | 172 | "outputs": [], |
182 | 173 | "source": [ |
183 | 174 | "phones = {\n", |
184 | | - " 'Jake': ['343-342-5455', '343-656-8766'],\n", |
185 | | - " 'John': ['693-232-5776'],\n", |
186 | | - " 'Maria': ['656-233-5555'],\n", |
187 | | - " 'Panos': ['212-998-0803', '917-888-4455', '800-929-2923']\n", |
| 175 | + " \"Jake\": [\"343-342-5455\", \"343-656-8766\"],\n", |
| 176 | + " \"John\": [\"693-232-5776\"],\n", |
| 177 | + " \"Maria\": [\"656-233-5555\"],\n", |
| 178 | + " \"Panos\": [\"212-998-0803\", \"917-888-4455\", \"800-929-2923\"],\n", |
188 | 179 | "}" |
189 | 180 | ] |
190 | 181 | }, |
|
201 | 192 | "metadata": {}, |
202 | 193 | "outputs": [], |
203 | 194 | "source": [ |
204 | | - "phones['Panos']" |
| 195 | + "phones[\"Panos\"]" |
205 | 196 | ] |
206 | 197 | }, |
207 | 198 | { |
|
217 | 208 | "metadata": {}, |
218 | 209 | "outputs": [], |
219 | 210 | "source": [ |
220 | | - "phones.get('Panos')" |
| 211 | + "phones.get(\"Panos\")" |
221 | 212 | ] |
222 | 213 | }, |
223 | 214 | { |
|
233 | 224 | "metadata": {}, |
234 | 225 | "outputs": [], |
235 | 226 | "source": [ |
236 | | - "phones['Panos'][1]" |
| 227 | + "phones[\"Panos\"][1]" |
237 | 228 | ] |
238 | 229 | }, |
239 | 230 | { |
|
242 | 233 | "metadata": {}, |
243 | 234 | "outputs": [], |
244 | 235 | "source": [ |
245 | | - "phones.get('Panos')[1]" |
| 236 | + "phones.get(\"Panos\")[1]" |
246 | 237 | ] |
247 | 238 | }, |
248 | 239 | { |
|
259 | 250 | "outputs": [], |
260 | 251 | "source": [ |
261 | 252 | "phones = {\n", |
262 | | - " \"Panos\": {\"Work\":\"212-998-0803\", \"Cell\": \"917-888-4455\"},\n", |
263 | | - " \"Maria\": {\"Work\":\"656-233-5555\"},\n", |
264 | | - " \"John\": {\"Cell\":\"693-232-5776\"},\n", |
265 | | - " \"Jake\": {\"Home\":\"415-794-3423\"}\n", |
| 253 | + " \"Panos\": {\"Work\": \"212-998-0803\", \"Cell\": \"917-888-4455\"},\n", |
| 254 | + " \"Maria\": {\"Work\": \"656-233-5555\"},\n", |
| 255 | + " \"John\": {\"Cell\": \"693-232-5776\"},\n", |
| 256 | + " \"Jake\": {\"Home\": \"415-794-3423\"},\n", |
266 | 257 | "}" |
267 | 258 | ] |
268 | 259 | }, |
|
272 | 263 | "metadata": {}, |
273 | 264 | "outputs": [], |
274 | 265 | "source": [ |
275 | | - "phones['Panos']['Cell']" |
| 266 | + "phones[\"Panos\"][\"Cell\"]" |
276 | 267 | ] |
277 | 268 | }, |
278 | 269 | { |
|
289 | 280 | "outputs": [], |
290 | 281 | "source": [ |
291 | 282 | "citibike_stations = [\n", |
292 | | - " {'station_id': 72, 'capacity': 39, 'coords': {'lon': -73.9939, 'lat': 40.7673}, 'name': 'W 52 St & 11 Ave', },\n", |
293 | | - " {'station_id': 79, 'capacity': 33, 'coords': {'lon': -74.0067, 'lat': 40.7191}, 'name': 'Franklin St & W Broadway'},\n", |
294 | | - " {'station_id': 82, 'capacity': 27, 'coords': {'lon': -74.0002, 'lat': 40.7673}, 'name': 'St James Pl & Pearl St'},\n", |
295 | | - " {'station_id': 83, 'capacity': 62, 'coords': {'lon': -73.9763, 'lat': 40.6838}, 'name': 'Atlantic Ave & Fort Greene Pl'},\n", |
296 | | - " {'station_id': 116, 'capacity': 39, 'coords': {'lon': -74.0015, 'lat': 40.7418}, 'name': 'W 17 St & 8 Ave'}\n", |
| 283 | + " {\n", |
| 284 | + " \"station_id\": 72,\n", |
| 285 | + " \"capacity\": 39,\n", |
| 286 | + " \"coords\": {\"lon\": -73.9939, \"lat\": 40.7673},\n", |
| 287 | + " \"name\": \"W 52 St & 11 Ave\",\n", |
| 288 | + " },\n", |
| 289 | + " {\n", |
| 290 | + " \"station_id\": 79,\n", |
| 291 | + " \"capacity\": 33,\n", |
| 292 | + " \"coords\": {\"lon\": -74.0067, \"lat\": 40.7191},\n", |
| 293 | + " \"name\": \"Franklin St & W Broadway\",\n", |
| 294 | + " },\n", |
| 295 | + " {\n", |
| 296 | + " \"station_id\": 82,\n", |
| 297 | + " \"capacity\": 27,\n", |
| 298 | + " \"coords\": {\"lon\": -74.0002, \"lat\": 40.7673},\n", |
| 299 | + " \"name\": \"St James Pl & Pearl St\",\n", |
| 300 | + " },\n", |
| 301 | + " {\n", |
| 302 | + " \"station_id\": 83,\n", |
| 303 | + " \"capacity\": 62,\n", |
| 304 | + " \"coords\": {\"lon\": -73.9763, \"lat\": 40.6838},\n", |
| 305 | + " \"name\": \"Atlantic Ave & Fort Greene Pl\",\n", |
| 306 | + " },\n", |
| 307 | + " {\n", |
| 308 | + " \"station_id\": 116,\n", |
| 309 | + " \"capacity\": 39,\n", |
| 310 | + " \"coords\": {\"lon\": -74.0015, \"lat\": 40.7418},\n", |
| 311 | + " \"name\": \"W 17 St & 8 Ave\",\n", |
| 312 | + " },\n", |
297 | 313 | "]" |
298 | 314 | ] |
299 | 315 | }, |
|
321 | 337 | "outputs": [], |
322 | 338 | "source": [ |
323 | 339 | "# Get the name for the first station\n", |
324 | | - "citibike_stations[0]['name']" |
| 340 | + "citibike_stations[0][\"name\"]" |
325 | 341 | ] |
326 | 342 | }, |
327 | 343 | { |
|
337 | 353 | "metadata": {}, |
338 | 354 | "outputs": [], |
339 | 355 | "source": [ |
340 | | - "citibike_stations[0]['coords']" |
| 356 | + "citibike_stations[0][\"coords\"]" |
341 | 357 | ] |
342 | 358 | }, |
343 | 359 | { |
|
353 | 369 | "metadata": {}, |
354 | 370 | "outputs": [], |
355 | 371 | "source": [ |
356 | | - "citibike_stations[0]['coords']['lat']" |
| 372 | + "citibike_stations[0][\"coords\"][\"lat\"]" |
357 | 373 | ] |
358 | 374 | }, |
359 | 375 | { |
|
403 | 419 | "outputs": [], |
404 | 420 | "source": [ |
405 | 421 | "data = {\n", |
406 | | - " \"Panos\": {\n", |
407 | | - " \"Job\": \"Professor\",\n", |
408 | | - " \"YOB\": \"1976\",\n", |
409 | | - " \"Children\": [\"Gregory\", \"Anna\"]\n", |
410 | | - " },\n", |
411 | | - " \"Joe\": {\n", |
412 | | - " \"Job\": \"Data Scientist\",\n", |
413 | | - " \"YOB\": \"1981\"\n", |
414 | | - " }\n", |
| 422 | + " \"Panos\": {\"Job\": \"Professor\", \"YOB\": \"1976\", \"Children\": [\"Gregory\", \"Anna\"]},\n", |
| 423 | + " \"Joe\": {\"Job\": \"Data Scientist\", \"YOB\": \"1981\"},\n", |
415 | 424 | "}" |
416 | 425 | ] |
417 | 426 | }, |
|
457 | 466 | "metadata": {}, |
458 | 467 | "outputs": [], |
459 | 468 | "source": [ |
460 | | - "# Prints the number of people _entries_ in the data. \n", |
| 469 | + "# Prints the number of people _entries_ in the data.\n", |
461 | 470 | "# (Notice that it is much harder to find all the people in the data, eg the children)" |
462 | 471 | ] |
463 | 472 | }, |
|
501 | 510 | { |
502 | 511 | "cell_type": "markdown", |
503 | 512 | "metadata": { |
504 | | - "solution2": "shown", |
| 513 | + "solution2": "hidden", |
505 | 514 | "solution2_first": true |
506 | 515 | }, |
507 | 516 | "source": [ |
|
512 | 521 | "cell_type": "code", |
513 | 522 | "execution_count": null, |
514 | 523 | "metadata": { |
515 | | - "solution2": "shown" |
| 524 | + "solution2": "hidden" |
516 | 525 | }, |
517 | 526 | "outputs": [], |
518 | 527 | "source": [ |
519 | 528 | "# Prints the job of Joe\n", |
520 | | - "data['Joe']['Job']" |
| 529 | + "data[\"Joe\"][\"Job\"]" |
521 | 530 | ] |
522 | 531 | }, |
523 | 532 | { |
524 | 533 | "cell_type": "code", |
525 | 534 | "execution_count": null, |
526 | 535 | "metadata": { |
527 | | - "solution2": "shown" |
| 536 | + "solution2": "hidden" |
528 | 537 | }, |
529 | 538 | "outputs": [], |
530 | 539 | "source": [ |
531 | 540 | "# Prints the year of birth of Panos\n", |
532 | | - "data['Panos']['YOB']" |
| 541 | + "data[\"Panos\"][\"YOB\"]" |
533 | 542 | ] |
534 | 543 | }, |
535 | 544 | { |
536 | 545 | "cell_type": "code", |
537 | 546 | "execution_count": null, |
538 | 547 | "metadata": { |
539 | | - "solution2": "shown" |
| 548 | + "solution2": "hidden" |
540 | 549 | }, |
541 | 550 | "outputs": [], |
542 | 551 | "source": [ |
543 | 552 | "# Prints the children of Panos\n", |
544 | | - "data['Panos']['Children']" |
| 553 | + "data[\"Panos\"][\"Children\"]" |
545 | 554 | ] |
546 | 555 | }, |
547 | 556 | { |
548 | 557 | "cell_type": "code", |
549 | 558 | "execution_count": null, |
550 | 559 | "metadata": { |
551 | | - "solution2": "shown" |
| 560 | + "solution2": "hidden" |
552 | 561 | }, |
553 | 562 | "outputs": [], |
554 | 563 | "source": [ |
555 | 564 | "# Prints the second child of Panos\n", |
556 | | - "data['Panos']['Children'][1]" |
| 565 | + "data[\"Panos\"][\"Children\"][1]" |
557 | 566 | ] |
558 | 567 | }, |
559 | 568 | { |
560 | 569 | "cell_type": "code", |
561 | 570 | "execution_count": null, |
562 | 571 | "metadata": { |
563 | | - "solution2": "shown" |
| 572 | + "solution2": "hidden" |
564 | 573 | }, |
565 | 574 | "outputs": [], |
566 | 575 | "source": [ |
567 | 576 | "# Checks if Maria is in the data\n", |
568 | | - "'Maria' in data.keys()" |
| 577 | + "\"Maria\" in data.keys()" |
569 | 578 | ] |
570 | 579 | }, |
571 | 580 | { |
572 | 581 | "cell_type": "code", |
573 | 582 | "execution_count": null, |
574 | 583 | "metadata": { |
575 | | - "solution2": "shown" |
| 584 | + "solution2": "hidden" |
576 | 585 | }, |
577 | 586 | "outputs": [], |
578 | 587 | "source": [ |
579 | 588 | "# Checks if Maria is in the data, simpler\n", |
580 | | - "'Maria' in data" |
| 589 | + "\"Maria\" in data" |
581 | 590 | ] |
582 | 591 | }, |
583 | 592 | { |
584 | 593 | "cell_type": "code", |
585 | 594 | "execution_count": null, |
586 | 595 | "metadata": { |
587 | | - "solution2": "shown" |
| 596 | + "solution2": "hidden" |
588 | 597 | }, |
589 | 598 | "outputs": [], |
590 | 599 | "source": [ |
591 | 600 | "# Checks if Anna is in the data\n", |
592 | | - "'Anna' in data\n", |
| 601 | + "\"Anna\" in data\n", |
593 | 602 | "# Notice that the in command *will not* look into the values\n", |
594 | 603 | "# We need to use much more complex code to check all the data, beyond the keys" |
595 | 604 | ] |
|
598 | 607 | "cell_type": "code", |
599 | 608 | "execution_count": null, |
600 | 609 | "metadata": { |
601 | | - "solution2": "shown" |
| 610 | + "solution2": "hidden" |
602 | 611 | }, |
603 | 612 | "outputs": [], |
604 | 613 | "source": [ |
|
610 | 619 | "cell_type": "code", |
611 | 620 | "execution_count": null, |
612 | 621 | "metadata": { |
613 | | - "solution2": "shown" |
| 622 | + "solution2": "hidden" |
614 | 623 | }, |
615 | 624 | "outputs": [], |
616 | 625 | "source": [ |
|
622 | 631 | "cell_type": "code", |
623 | 632 | "execution_count": null, |
624 | 633 | "metadata": { |
625 | | - "solution2": "shown" |
| 634 | + "solution2": "hidden" |
626 | 635 | }, |
627 | 636 | "outputs": [], |
628 | 637 | "source": [ |
|
648 | 657 | "name": "python", |
649 | 658 | "nbconvert_exporter": "python", |
650 | 659 | "pygments_lexer": "ipython3", |
651 | | - "version": "3.5.2" |
| 660 | + "version": "3.8.2" |
652 | 661 | } |
653 | 662 | }, |
654 | 663 | "nbformat": 4, |
|
0 commit comments