{ "cells": [ { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "EluRo1fC7YSm" }, "source": [ "# Introduction to Python \n", "\n", "### Comprehensions and Functional Programming" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "T586rDGKGiEb" }, "source": [ "#### 1) Use list comprehension to create a list that:\n", "\n", "- a) Given a list of strings, contains the length of them.\n", "\n", "- b) Contains all the cubes of the multiples of 17 in a range from 1 to 1000.\n", "\n", "- c) Contains all the numbers from 1 to 100 that starts with 4 or 5 and are even numbers.\n", "\n", "- d) Contains all the numbers from 1 to 1000 that have the digit 3 in them.\n", "\n", "- e) Given a list of strings, transform to upper if the first letter is a vowel and invert the string otherwise.\n", "\n", " For example, ['apple', 'orange', 'watermelon'] -> ['APPLE','ORANGE', 'nolemretaw']" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "X73tSdOdHJNN" }, "source": [ "#### 2) Write a function that takes a list with two numbers in it and determines if the sum of the digits of the two numbers are equal to each other." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "am_e92rCHNJ-" }, "source": [ "#### 3) Among all the numbers that are made from the product of two 3-digit numbers:\n", "\n", "- a) How many are odd numbers?\n", "\n", "- b) How many start with the digit \"8\" and ends with the digit \"9\"\n", "\n", "- c) How many are palindromes?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "IJ5A3ICXT56U" }, "source": [ "#### 4) Use functional programming to:" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "CQjX0itUV28B" }, "source": [ "- a) Filter the indexes with positive changes in the dictionary 'stock_indexes'. \n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "colab": {}, "colab_type": "code", "id": "x3nUtcLmWNso" }, "outputs": [], "source": [ "stock_indexes = {'FTSE 100':-0.3, 'DAX': -1.65, 'Dow Jones': -1.1, 'Ibovespa':0.2, 'S&P':0.65}" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "sWzE6gJLWjW3" }, "source": [ "- b) Apply a function that generates a list with the types of each element of the list 'elements'" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "colab": {}, "colab_type": "code", "id": "lHyUqNnMX3D2" }, "outputs": [], "source": [ "elements = [1,'economics', 9.8, 2 + 3j, ['a','b','c'], stock_indexes]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "_gW12Ti2YM1J" }, "source": [ "- c) Transform a list of lists in a flat list\n", " \n", " For example, [[1,2,4],[10,12,14],[1,2]] -> [1,2,4,10,12,14,1,2]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "colab": { "collapsed_sections": [], "name": "2nd_Assignment.ipynb", "provenance": [] }, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }