my_list = [i**2 for i in range(0,101,1)]
my_list_2 = [i**2 for i in range(0, 11, 1) if i % 3 != 0]
my_list_2
my_list_3 = [i for i in range(0, 100000, 1) if (i % 4 == 0 and i % 6 == 0 and i % 9 == 0)]
def run():
dict_1 = {i: i**3 for i in range(1, 101)}
print(dict_1)
if __name__ == '__main__':
run()
{1: 1, 2: 8, 3: 27, 4: 64, 5: 125, 6: 216, 7: 343, 8: 512, 9: 729, 10: 1000, 11: 1331, 12: 1728, 13: 2197, 14: 2744, 15: 3375, 16: 4096, 17: 4913, 18: 5832, 19: 6859, 20: 8000, 21: 9261, 22: 10648, 23: 12167, 24: 13824, 25: 15625, 26: 17576, 27: 19683, 28: 21952, 29: 24389, 30: 27000, 31: 29791, 32: 32768, 33: 35937, 34: 39304, 35: 42875, 36: 46656, 37: 50653, 38: 54872, 39: 59319, 40: 64000, 41: 68921, 42: 74088, 43: 79507, 44: 85184, 45: 91125, 46: 97336, 47: 103823, 48: 110592, 49: 117649, 50: 125000, 51: 132651, 52: 140608, 53: 148877, 54: 157464, 55: 166375, 56: 175616, 57: 185193, 58: 195112, 59: 205379, 60: 216000, 61: 226981, 62: 238328, 63: 250047, 64: 262144, 65: 274625, 66: 287496, 67: 300763, 68: 314432, 69: 328509, 70: 343000, 71: 357911, 72: 373248, 73: 389017, 74: 405224, 75: 421875, 76: 438976, 77: 456533, 78: 474552, 79: 493039, 80: 512000, 81: 531441, 82: 551368, 83: 571787, 84: 592704, 85: 614125, 86: 636056, 87: 658503, 88: 681472, 89: 704969, 90: 729000, 91: 753571, 92: 778688, 93: 804357, 94: 830584, 95: 857375, 96: 884736, 97: 912673, 98: 941192, 99: 970299, 100: 1000000}
def run():
dict_1 = {i: i**3 for i in range(1, 101) if i % 3 != 0}
print(dict_1)
if __name__ == '__main__':
run()
{1: 1, 2: 8, 4: 64, 5: 125, 7: 343, 8: 512, 10: 1000, 11: 1331, 13: 2197, 14: 2744, 16: 4096, 17: 4913, 19: 6859, 20: 8000, 22: 10648, 23: 12167, 25: 15625, 26: 17576, 28: 21952, 29: 24389, 31: 29791, 32: 32768, 34: 39304, 35: 42875, 37: 50653, 38: 54872, 40: 64000, 41: 68921, 43: 79507, 44: 85184, 46: 97336, 47: 103823, 49: 117649, 50: 125000, 52: 140608, 53: 148877, 55: 166375, 56: 175616, 58: 195112, 59: 205379, 61: 226981, 62: 238328, 64: 262144, 65: 274625, 67: 300763, 68: 314432, 70: 343000, 71: 357911, 73: 389017, 74: 405224, 76: 438976, 77: 456533, 79: 493039, 80: 512000, 82: 551368, 83: 571787, 85: 614125, 86: 636056, 88: 681472, 89: 704969, 91: 753571, 92: 778688, 94: 830584, 95: 857375, 97: 912673, 98: 941192, 100: 1000000}
def run():
dict_2 = {i: round(i**(1/2), 2) for i in range(1, 1001)}
print(dict_2)
if __name__ == '__main__':
run()
{1: 1.0, 2: 1.41, 3: 1.73, 4: 2.0, 5: 2.24, 6: 2.45, 7: 2.65, 8: 2.83, 9: 3.0, 10: 3.16, 11: 3.32, 12: 3.46, 13: 3.61, 14: 3.74, 15: 3.87, 16: 4.0, 17: 4.12, 18: 4.24, 19: 4.36, 20: 4.47, 21: 4.58, 22: 4.69, 23: 4.8, 24: 4.9, 25: 5.0, 26: 5.1, 27: 5.2, 28: 5.29, 29: 5.39, 30: 5.48, 31: 5.57, 32: 5.66, 33: 5.74, 34: 5.83, 35: 5.92, 36: 6.0, 37: 6.08, 38: 6.16, 39: 6.24, 40: 6.32, 41: 6.4, 42: 6.48, 43: 6.56, 44: 6.63, 45: 6.71, 46: 6.78, 47: 6.86, 48: 6.93, 49: 7.0, 50: 7.07, 51: 7.14, 52: 7.21, 53: 7.28, 54: 7.35, 55: 7.42, 56: 7.48, 57: 7.55, 58: 7.62, 59: 7.68, 60: 7.75, 61: 7.81, 62: 7.87, 63: 7.94, 64: 8.0, 65: 8.06, 66: 8.12, 67: 8.19, 68: 8.25, 69: 8.31, 70: 8.37, 71: 8.43, 72: 8.49, 73: 8.54, 74: 8.6, 75: 8.66, 76: 8.72, 77: 8.77, 78: 8.83, 79: 8.89, 80: 8.94, 81: 9.0, 82: 9.06, 83: 9.11, 84: 9.17, 85: 9.22, 86: 9.27, 87: 9.33, 88: 9.38, 89: 9.43, 90: 9.49, 91: 9.54, 92: 9.59, 93: 9.64, 94: 9.7, 95: 9.75, 96: 9.8, 97: 9.85, 98: 9.9, 99: 9.95, 100: 10.0, 101: 10.05, 102: 10.1, 103: 10.15, 104: 10.2, 105: 10.25, 106: 10.3, 107: 10.34, 108: 10.39, 109: 10.44, 110: 10.49, 111: 10.54, 112: 10.58, 113: 10.63, 114: 10.68, 115: 10.72, 116: 10.77, 117: 10.82, 118: 10.86, 119: 10.91, 120: 10.95, 121: 11.0, 122: 11.05, 123: 11.09, 124: 11.14, 125: 11.18, 126: 11.22, 127: 11.27, 128: 11.31, 129: 11.36, 130: 11.4, 131: 11.45, 132: 11.49, 133: 11.53, 134: 11.58, 135: 11.62, 136: 11.66, 137: 11.7, 138: 11.75, 139: 11.79, 140: 11.83, 141: 11.87, 142: 11.92, 143: 11.96, 144: 12.0, 145: 12.04, 146: 12.08, 147: 12.12, 148: 12.17, 149: 12.21, 150: 12.25, 151: 12.29, 152: 12.33, 153: 12.37, 154: 12.41, 155: 12.45, 156: 12.49, 157: 12.53, 158: 12.57, 159: 12.61, 160: 12.65, 161: 12.69, 162: 12.73, 163: 12.77, 164: 12.81, 165: 12.85, 166: 12.88, 167: 12.92, 168: 12.96, 169: 13.0, 170: 13.04, 171: 13.08, 172: 13.11, 173: 13.15, 174: 13.19, 175: 13.23, 176: 13.27, 177: 13.3, 178: 13.34, 179: 13.38, 180: 13.42, 181: 13.45, 182: 13.49, 183: 13.53, 184: 13.56, 185: 13.6, 186: 13.64, 187: 13.67, 188: 13.71, 189: 13.75, 190: 13.78, 191: 13.82, 192: 13.86, 193: 13.89, 194: 13.93, 195: 13.96, 196: 14.0, 197: 14.04, 198: 14.07, 199: 14.11, 200: 14.14, 201: 14.18, 202: 14.21, 203: 14.25, 204: 14.28, 205: 14.32, 206: 14.35, 207: 14.39, 208: 14.42, 209: 14.46, 210: 14.49, 211: 14.53, 212: 14.56, 213: 14.59, 214: 14.63, 215: 14.66, 216: 14.7, 217: 14.73, 218: 14.76, 219: 14.8, 220: 14.83, 221: 14.87, 222: 14.9, 223: 14.93, 224: 14.97, 225: 15.0, 226: 15.03, 227: 15.07, 228: 15.1, 229: 15.13, 230: 15.17, 231: 15.2, 232: 15.23, 233: 15.26, 234: 15.3, 235: 15.33, 236: 15.36, 237: 15.39, 238: 15.43, 239: 15.46, 240: 15.49, 241: 15.52, 242: 15.56, 243: 15.59, 244: 15.62, 245: 15.65, 246: 15.68, 247: 15.72, 248: 15.75, 249: 15.78, 250: 15.81, 251: 15.84, 252: 15.87, 253: 15.91, 254: 15.94, 255: 15.97, 256: 16.0, 257: 16.03, 258: 16.06, 259: 16.09, 260: 16.12, 261: 16.16, 262: 16.19, 263: 16.22, 264: 16.25, 265: 16.28, 266: 16.31, 267: 16.34, 268: 16.37, 269: 16.4, 270: 16.43, 271: 16.46, 272: 16.49, 273: 16.52, 274: 16.55, 275: 16.58, 276: 16.61, 277: 16.64, 278: 16.67, 279: 16.7, 280: 16.73, 281: 16.76, 282: 16.79, 283: 16.82, 284: 16.85, 285: 16.88, 286: 16.91, 287: 16.94, 288: 16.97, 289: 17.0, 290: 17.03, 291: 17.06, 292: 17.09, 293: 17.12, 294: 17.15, 295: 17.18, 296: 17.2, 297: 17.23, 298: 17.26, 299: 17.29, 300: 17.32, 301: 17.35, 302: 17.38, 303: 17.41, 304: 17.44, 305: 17.46, 306: 17.49, 307: 17.52, 308: 17.55, 309: 17.58, 310: 17.61, 311: 17.64, 312: 17.66, 313: 17.69, 314: 17.72, 315: 17.75, 316: 17.78, 317: 17.8, 318: 17.83, 319: 17.86, 320: 17.89, 321: 17.92, 322: 17.94, 323: 17.97, 324: 18.0, 325: 18.03, 326: 18.06, 327: 18.08, 328: 18.11, 329: 18.14, 330: 18.17, 331: 18.19, 332: 18.22, 333: 18.25, 334: 18.28, 335: 18.3, 336: 18.33, 337: 18.36, 338: 18.38, 339: 18.41, 340: 18.44, 341: 18.47, 342: 18.49, 343: 18.52, 344: 18.55, 345: 18.57, 346: 18.6, 347: 18.63, 348: 18.65, 349: 18.68, 350: 18.71, 351: 18.73, 352: 18.76, 353: 18.79, 354: 18.81, 355: 18.84, 356: 18.87, 357: 18.89, 358: 18.92, 359: 18.95, 360: 18.97, 361: 19.0, 362: 19.03, 363: 19.05, 364: 19.08, 365: 19.1, 366: 19.13, 367: 19.16, 368: 19.18, 369: 19.21, 370: 19.24, 371: 19.26, 372: 19.29, 373: 19.31, 374: 19.34, 375: 19.36, 376: 19.39, 377: 19.42, 378: 19.44, 379: 19.47, 380: 19.49, 381: 19.52, 382: 19.54, 383: 19.57, 384: 19.6, 385: 19.62, 386: 19.65, 387: 19.67, 388: 19.7, 389: 19.72, 390: 19.75, 391: 19.77, 392: 19.8, 393: 19.82, 394: 19.85, 395: 19.87, 396: 19.9, 397: 19.92, 398: 19.95, 399: 19.97, 400: 20.0, 401: 20.02, 402: 20.05, 403: 20.07, 404: 20.1, 405: 20.12, 406: 20.15, 407: 20.17, 408: 20.2, 409: 20.22, 410: 20.25, 411: 20.27, 412: 20.3, 413: 20.32, 414: 20.35, 415: 20.37, 416: 20.4, 417: 20.42, 418: 20.45, 419: 20.47, 420: 20.49, 421: 20.52, 422: 20.54, 423: 20.57, 424: 20.59, 425: 20.62, 426: 20.64, 427: 20.66, 428: 20.69, 429: 20.71, 430: 20.74, 431: 20.76, 432: 20.78, 433: 20.81, 434: 20.83, 435: 20.86, 436: 20.88, 437: 20.9, 438: 20.93, 439: 20.95, 440: 20.98, 441: 21.0, 442: 21.02, 443: 21.05, 444: 21.07, 445: 21.1, 446: 21.12, 447: 21.14, 448: 21.17, 449: 21.19, 450: 21.21, 451: 21.24, 452: 21.26, 453: 21.28, 454: 21.31, 455: 21.33, 456: 21.35, 457: 21.38, 458: 21.4, 459: 21.42, 460: 21.45, 461: 21.47, 462: 21.49, 463: 21.52, 464: 21.54, 465: 21.56, 466: 21.59, 467: 21.61, 468: 21.63, 469: 21.66, 470: 21.68, 471: 21.7, 472: 21.73, 473: 21.75, 474: 21.77, 475: 21.79, 476: 21.82, 477: 21.84, 478: 21.86, 479: 21.89, 480: 21.91, 481: 21.93, 482: 21.95, 483: 21.98, 484: 22.0, 485: 22.02, 486: 22.05, 487: 22.07, 488: 22.09, 489: 22.11, 490: 22.14, 491: 22.16, 492: 22.18, 493: 22.2, 494: 22.23, 495: 22.25, 496: 22.27, 497: 22.29, 498: 22.32, 499: 22.34, 500: 22.36, 501: 22.38, 502: 22.41, 503: 22.43, 504: 22.45, 505: 22.47, 506: 22.49, 507: 22.52, 508: 22.54, 509: 22.56, 510: 22.58, 511: 22.61, 512: 22.63, 513: 22.65, 514: 22.67, 515: 22.69, 516: 22.72, 517: 22.74, 518: 22.76, 519: 22.78, 520: 22.8, 521: 22.83, 522: 22.85, 523: 22.87, 524: 22.89, 525: 22.91, 526: 22.93, 527: 22.96, 528: 22.98, 529: 23.0, 530: 23.02, 531: 23.04, 532: 23.07, 533: 23.09, 534: 23.11, 535: 23.13, 536: 23.15, 537: 23.17, 538: 23.19, 539: 23.22, 540: 23.24, 541: 23.26, 542: 23.28, 543: 23.3, 544: 23.32, 545: 23.35, 546: 23.37, 547: 23.39, 548: 23.41, 549: 23.43, 550: 23.45, 551: 23.47, 552: 23.49, 553: 23.52, 554: 23.54, 555: 23.56, 556: 23.58, 557: 23.6, 558: 23.62, 559: 23.64, 560: 23.66, 561: 23.69, 562: 23.71, 563: 23.73, 564: 23.75, 565: 23.77, 566: 23.79, 567: 23.81, 568: 23.83, 569: 23.85, 570: 23.87, 571: 23.9, 572: 23.92, 573: 23.94, 574: 23.96, 575: 23.98, 576: 24.0, 577: 24.02, 578: 24.04, 579: 24.06, 580: 24.08, 581: 24.1, 582: 24.12, 583: 24.15, 584: 24.17, 585: 24.19, 586: 24.21, 587: 24.23, 588: 24.25, 589: 24.27, 590: 24.29, 591: 24.31, 592: 24.33, 593: 24.35, 594: 24.37, 595: 24.39, 596: 24.41, 597: 24.43, 598: 24.45, 599: 24.47, 600: 24.49, 601: 24.52, 602: 24.54, 603: 24.56, 604: 24.58, 605: 24.6, 606: 24.62, 607: 24.64, 608: 24.66, 609: 24.68, 610: 24.7, 611: 24.72, 612: 24.74, 613: 24.76, 614: 24.78, 615: 24.8, 616: 24.82, 617: 24.84, 618: 24.86, 619: 24.88, 620: 24.9, 621: 24.92, 622: 24.94, 623: 24.96, 624: 24.98, 625: 25.0, 626: 25.02, 627: 25.04, 628: 25.06, 629: 25.08, 630: 25.1, 631: 25.12, 632: 25.14, 633: 25.16, 634: 25.18, 635: 25.2, 636: 25.22, 637: 25.24, 638: 25.26, 639: 25.28, 640: 25.3, 641: 25.32, 642: 25.34, 643: 25.36, 644: 25.38, 645: 25.4, 646: 25.42, 647: 25.44, 648: 25.46, 649: 25.48, 650: 25.5, 651: 25.51, 652: 25.53, 653: 25.55, 654: 25.57, 655: 25.59, 656: 25.61, 657: 25.63, 658: 25.65, 659: 25.67, 660: 25.69, 661: 25.71, 662: 25.73, 663: 25.75, 664: 25.77, 665: 25.79, 666: 25.81, 667: 25.83, 668: 25.85, 669: 25.87, 670: 25.88, 671: 25.9, 672: 25.92, 673: 25.94, 674: 25.96, 675: 25.98, 676: 26.0, 677: 26.02, 678: 26.04, 679: 26.06, 680: 26.08, 681: 26.1, 682: 26.12, 683: 26.13, 684: 26.15, 685: 26.17, 686: 26.19, 687: 26.21, 688: 26.23, 689: 26.25, 690: 26.27, 691: 26.29, 692: 26.31, 693: 26.32, 694: 26.34, 695: 26.36, 696: 26.38, 697: 26.4, 698: 26.42, 699: 26.44, 700: 26.46, 701: 26.48, 702: 26.5, 703: 26.51, 704: 26.53, 705: 26.55, 706: 26.57, 707: 26.59, 708: 26.61, 709: 26.63, 710: 26.65, 711: 26.66, 712: 26.68, 713: 26.7, 714: 26.72, 715: 26.74, 716: 26.76, 717: 26.78, 718: 26.8, 719: 26.81, 720: 26.83, 721: 26.85, 722: 26.87, 723: 26.89, 724: 26.91, 725: 26.93, 726: 26.94, 727: 26.96, 728: 26.98, 729: 27.0, 730: 27.02, 731: 27.04, 732: 27.06, 733: 27.07, 734: 27.09, 735: 27.11, 736: 27.13, 737: 27.15, 738: 27.17, 739: 27.18, 740: 27.2, 741: 27.22, 742: 27.24, 743: 27.26, 744: 27.28, 745: 27.29, 746: 27.31, 747: 27.33, 748: 27.35, 749: 27.37, 750: 27.39, 751: 27.4, 752: 27.42, 753: 27.44, 754: 27.46, 755: 27.48, 756: 27.5, 757: 27.51, 758: 27.53, 759: 27.55, 760: 27.57, 761: 27.59, 762: 27.6, 763: 27.62, 764: 27.64, 765: 27.66, 766: 27.68, 767: 27.69, 768: 27.71, 769: 27.73, 770: 27.75, 771: 27.77, 772: 27.78, 773: 27.8, 774: 27.82, 775: 27.84, 776: 27.86, 777: 27.87, 778: 27.89, 779: 27.91, 780: 27.93, 781: 27.95, 782: 27.96, 783: 27.98, 784: 28.0, 785: 28.02, 786: 28.04, 787: 28.05, 788: 28.07, 789: 28.09, 790: 28.11, 791: 28.12, 792: 28.14, 793: 28.16, 794: 28.18, 795: 28.2, 796: 28.21, 797: 28.23, 798: 28.25, 799: 28.27, 800: 28.28, 801: 28.3, 802: 28.32, 803: 28.34, 804: 28.35, 805: 28.37, 806: 28.39, 807: 28.41, 808: 28.43, 809: 28.44, 810: 28.46, 811: 28.48, 812: 28.5, 813: 28.51, 814: 28.53, 815: 28.55, 816: 28.57, 817: 28.58, 818: 28.6, 819: 28.62, 820: 28.64, 821: 28.65, 822: 28.67, 823: 28.69, 824: 28.71, 825: 28.72, 826: 28.74, 827: 28.76, 828: 28.77, 829: 28.79, 830: 28.81, 831: 28.83, 832: 28.84, 833: 28.86, 834: 28.88, 835: 28.9, 836: 28.91, 837: 28.93, 838: 28.95, 839: 28.97, 840: 28.98, 841: 29.0, 842: 29.02, 843: 29.03, 844: 29.05, 845: 29.07, 846: 29.09, 847: 29.1, 848: 29.12, 849: 29.14, 850: 29.15, 851: 29.17, 852: 29.19, 853: 29.21, 854: 29.22, 855: 29.24, 856: 29.26, 857: 29.27, 858: 29.29, 859: 29.31, 860: 29.33, 861: 29.34, 862: 29.36, 863: 29.38, 864: 29.39, 865: 29.41, 866: 29.43, 867: 29.44, 868: 29.46, 869: 29.48, 870: 29.5, 871: 29.51, 872: 29.53, 873: 29.55, 874: 29.56, 875: 29.58, 876: 29.6, 877: 29.61, 878: 29.63, 879: 29.65, 880: 29.66, 881: 29.68, 882: 29.7, 883: 29.72, 884: 29.73, 885: 29.75, 886: 29.77, 887: 29.78, 888: 29.8, 889: 29.82, 890: 29.83, 891: 29.85, 892: 29.87, 893: 29.88, 894: 29.9, 895: 29.92, 896: 29.93, 897: 29.95, 898: 29.97, 899: 29.98, 900: 30.0, 901: 30.02, 902: 30.03, 903: 30.05, 904: 30.07, 905: 30.08, 906: 30.1, 907: 30.12, 908: 30.13, 909: 30.15, 910: 30.17, 911: 30.18, 912: 30.2, 913: 30.22, 914: 30.23, 915: 30.25, 916: 30.27, 917: 30.28, 918: 30.3, 919: 30.32, 920: 30.33, 921: 30.35, 922: 30.36, 923: 30.38, 924: 30.4, 925: 30.41, 926: 30.43, 927: 30.45, 928: 30.46, 929: 30.48, 930: 30.5, 931: 30.51, 932: 30.53, 933: 30.55, 934: 30.56, 935: 30.58, 936: 30.59, 937: 30.61, 938: 30.63, 939: 30.64, 940: 30.66, 941: 30.68, 942: 30.69, 943: 30.71, 944: 30.72, 945: 30.74, 946: 30.76, 947: 30.77, 948: 30.79, 949: 30.81, 950: 30.82, 951: 30.84, 952: 30.85, 953: 30.87, 954: 30.89, 955: 30.9, 956: 30.92, 957: 30.94, 958: 30.95, 959: 30.97, 960: 30.98, 961: 31.0, 962: 31.02, 963: 31.03, 964: 31.05, 965: 31.06, 966: 31.08, 967: 31.1, 968: 31.11, 969: 31.13, 970: 31.14, 971: 31.16, 972: 31.18, 973: 31.19, 974: 31.21, 975: 31.22, 976: 31.24, 977: 31.26, 978: 31.27, 979: 31.29, 980: 31.3, 981: 31.32, 982: 31.34, 983: 31.35, 984: 31.37, 985: 31.38, 986: 31.4, 987: 31.42, 988: 31.43, 989: 31.45, 990: 31.46, 991: 31.48, 992: 31.5, 993: 31.51, 994: 31.53, 995: 31.54, 996: 31.56, 997: 31.58, 998: 31.59, 999: 31.61, 1000: 31.62}
palindrome = lambda string: string == string[::-1]
palindrome("ana")
# Remover los números pares con list comprehension
l = [1, 4, 5, 6, 9, 13, 19, 21]
[ i for i in l if i % 2 != 0]
# Ahora con filter
l2 = list(filter(lambda x: x%2 != 0, l))
l2
# Elevar al cuadrado los elementos con list comprehensions
l3 = [1, 2, 3, 4, 5]
l4 = [i**2 for i in l3]
l4
# Ahora con map
l5 = list(map(lambda x: x**2, l3))
l5
l6 = [2, 2, 2, 2, 2]
all_multiplied = 1
for i in l6:
all_multiplied *= i
print(all_multiplied)
32
# Ahora con reduce
from functools import reduce
reduced = reduce(lambda a, b: a*b, l6)
print(reduced)
32
DATA = [
{
'name': 'Facundo',
'age': 72,
'organization': 'Platzi',
'position': 'Technical Coach',
'language': 'python',
},
{
'name': 'Luisana',
'age': 33,
'organization': 'Globant',
'position': 'UX Designer',
'language': 'javascript',
},
{
'name': 'Héctor',
'age': 19,
'organization': 'Platzi',
'position': 'Associate',
'language': 'ruby',
},
{
'name': 'Gabriel',
'age': 20,
'organization': 'Platzi',
'position': 'Associate',
'language': 'javascript',
},
{
'name': 'Isabella',
'age': 30,
'organization': 'Platzi',
'position': 'QA Manager',
'language': 'java',
},
{
'name': 'Karo',
'age': 23,
'organization': 'Everis',
'position': 'Backend Developer',
'language': 'python',
},
{
'name': 'Ariel',
'age': 32,
'organization': 'Rappi',
'position': 'Support',
'language': '',
},
{
'name': 'Juan',
'age': 17,
'organization': '',
'position': 'Student',
'language': 'go',
},
{
'name': 'Pablo',
'age': 32,
'organization': 'Master',
'position': 'Human Resources Manager',
'language': 'python',
},
{
'name': 'Lorena',
'age': 56,
'organization': 'Python Organization',
'position': 'Language Maker',
'language': 'python',
},
]
def run():
all_py_devs = [worker["name"] for worker in DATA if worker['language'] == "python"]
all_platzi_workers = [worker["name"] for worker in DATA if worker["organization"] == "Platzi"]
adults = list(filter(lambda worker: worker["age"] > 18, DATA))
adults = list(map(lambda worker: worker["name"], adults))
# | símbolo pipe: une un diccionario con otro nuevo.
old = list(map(lambda worker: worker | {"old": worker['age'] > 70}, DATA))
# ALTERNATIVA PARA VERSIONES ANTERIORES A 3.9:
# old_people = list(map(lambda worker: {**worker, **{"old": worker["age"] > 70}}, DATA))
for worker in old:
print(worker)
if __name__ == '__main__':
run()
{'name': 'Facundo', 'age': 72, 'organization': 'Platzi', 'position': 'Technical Coach', 'language': 'python', 'old': True}
{'name': 'Luisana', 'age': 33, 'organization': 'Globant', 'position': 'UX Designer', 'language': 'javascript', 'old': False}
{'name': 'Héctor', 'age': 19, 'organization': 'Platzi', 'position': 'Associate', 'language': 'ruby', 'old': False}
{'name': 'Gabriel', 'age': 20, 'organization': 'Platzi', 'position': 'Associate', 'language': 'javascript', 'old': False}
{'name': 'Isabella', 'age': 30, 'organization': 'Platzi', 'position': 'QA Manager', 'language': 'java', 'old': False}
{'name': 'Karo', 'age': 23, 'organization': 'Everis', 'position': 'Backend Developer', 'language': 'python', 'old': False}
{'name': 'Ariel', 'age': 32, 'organization': 'Rappi', 'position': 'Support', 'language': '', 'old': False}
{'name': 'Juan', 'age': 17, 'organization': '', 'position': 'Student', 'language': 'go', 'old': False}
{'name': 'Pablo', 'age': 32, 'organization': 'Master', 'position': 'Human Resources Manager', 'language': 'python', 'old': False}
{'name': 'Lorena', 'age': 56, 'organization': 'Python Organization', 'position': 'Language Maker', 'language': 'python', 'old': False}
all_py_devs = list(filter(lambda worker: worker['language'] == 'python', DATA))
all_py_devs = list(map(lambda worker: worker['name'], all_py_devs))
all_py_devs
all_platzi_workers = list(filter(lambda worker: worker['organization'] == 'Platzi', DATA))
all_platzi_workers = list(map(lambda worker: worker['name'], all_platzi_workers))
all_platzi_workers
adults = [worker['name'] for worker in DATA if worker['age']> 18]
adults
old_confirmation = lambda worker_age: worker_age > 70
old_people = [worker | {'old': old_confirmation(worker['age'])} for worker in DATA]
try:
<bloque1>
except <error> as <alias>:
<bloque 2>
Execution Error
SyntaxError: invalid syntax (<ipython-input-20-0340e3045114>, line 2)
raise <NombreError>("<descripci[on del error>")
def palindrome(string):
assert len(string) > 0, "No se puede ingresar una cadena vacía."
return string == string[::-1]
print(palindrome(""))
Execution Error
AssertionError: No se puede ingresar una cadena vacía.
def divisors(num):
divisors = [i for i in range(1, num+1) if num % i == 0]
return divisors
def run():
num = input("Ingresa un número: ")
assert num.isnumeric(), "Debes ingresar un número positivo" # .isnumeric devuelve True o False
print(divisors(int(num)))
print("End")
if __name__ == '__main__':
run()
[1, 1997]
End