diff --git a/Desafio_01.ipynb b/Desafio_01.ipynb index 49ee4db..0aa9fbe 100644 --- a/Desafio_01.ipynb +++ b/Desafio_01.ipynb @@ -18,7 +18,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.7" + "version": "3.7.9-final" }, "colab": { "name": "Desafio 1.ipynb", @@ -67,7 +67,7 @@ "\n", "# Seu código" ], - "execution_count": 0, + "execution_count": 22, "outputs": [] }, { @@ -78,10 +78,51 @@ "colab": {} }, "source": [ - "" + "# import necessary libraries\n", + "import numpy as np\n", + "from operator import itemgetter\n", + "\n", + "# get unique values and its frequencies\n", + "words, frequencies = np.unique(palavras, return_counts=True)" ], - "execution_count": 0, + "execution_count": 23, "outputs": [] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [], + "source": [ + "# zip words and frequencies for iteration\n", + "stats = list(zip(words, frequencies))" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Word: black\tFrequency: 5\nWord: eyes\tFrequency: 1\nWord: green\tFrequency: 4\nWord: orange\tFrequency: 4\nWord: pink\tFrequency: 6\nWord: red\tFrequency: 4\nWord: white\tFrequency: 5\n" + ] + } + ], + "source": [ + "# print the word and its frequency\n", + "for stat in stats:\n", + " print(f'Word: {itemgetter(0)(stat)}\\tFrequency: {itemgetter(1)(stat)}')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ] -} +} \ No newline at end of file diff --git a/Desafio_02.ipynb b/Desafio_02.ipynb index ee7f64b..bc88704 100644 --- a/Desafio_02.ipynb +++ b/Desafio_02.ipynb @@ -18,7 +18,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.7.9-final" }, "colab": { "name": "Desafio 2.ipynb", @@ -65,11 +65,79 @@ "colab": {} }, "source": [ - "def convert_to_sec(number):\n", - " pass # Seu código" + "def convert_to_sec(hours):\n", + " '''Converts hours to seconds'''\n", + " return hours * 60 * 60" ], - "execution_count": 0, + "execution_count": 1, "outputs": [] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "18000" + ] + }, + "metadata": {}, + "execution_count": 2 + } + ], + "source": [ + "convert_to_sec(5)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "10800" + ] + }, + "metadata": {}, + "execution_count": 3 + } + ], + "source": [ + "convert_to_sec(3)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "7200" + ] + }, + "metadata": {}, + "execution_count": 4 + } + ], + "source": [ + "convert_to_sec(2)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ] -} +} \ No newline at end of file diff --git a/Desafio_03.ipynb b/Desafio_03.ipynb index 1311cbd..53e484d 100644 --- a/Desafio_03.ipynb +++ b/Desafio_03.ipynb @@ -18,7 +18,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.7.9-final" }, "colab": { "name": "Desafio 3.ipynb", @@ -61,7 +61,7 @@ "\n", "# Seu código" ], - "execution_count": 0, + "execution_count": 3, "outputs": [] }, { @@ -72,10 +72,41 @@ "colab": {} }, "source": [ - "" + "# import necessary libraries\n", + "import numpy as np" ], - "execution_count": 0, + "execution_count": 4, "outputs": [] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "# get unique values and sort the list\n", + "un_values = sorted(np.unique(lista))" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "[1, 2, 3, 4, 5, 6, 9, 13, 15, 30, 45]" + ] + }, + "metadata": {}, + "execution_count": 11 + } + ], + "source": [ + "un_values" + ] } ] -} +} \ No newline at end of file diff --git a/Desafio_04.ipynb b/Desafio_04.ipynb index 089c3a8..b524c5e 100644 --- a/Desafio_04.ipynb +++ b/Desafio_04.ipynb @@ -18,7 +18,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.7.9-final" }, "colab": { "name": "Desafio 4.ipynb", @@ -61,9 +61,13 @@ "colab": {} }, "source": [ - "# Seu código" + "# Seu código\n", + "def reverse_text(phrase):\n", + " '''Reverses the order of words in a string'''\n", + " phrase = list(reversed(phrase.split(' ')))\n", + " return ' '.join(phrase)\n" ], - "execution_count": 0, + "execution_count": 2, "outputs": [] }, { @@ -74,10 +78,28 @@ "colab": {} }, "source": [ - "" + "reverse_text('Python é legal')" ], - "execution_count": 0, - "outputs": [] + "execution_count": 3, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'legal é Python'" + ] + }, + "metadata": {}, + "execution_count": 3 + } + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ] -} +} \ No newline at end of file diff --git a/Desafio_05.ipynb b/Desafio_05.ipynb index 204b1df..e90fa76 100644 --- a/Desafio_05.ipynb +++ b/Desafio_05.ipynb @@ -10,7 +10,8 @@ }, "kernelspec": { "name": "python3", - "display_name": "Python 3" + "display_name": "Python 3", + "language": "python" } }, "cells": [ @@ -68,7 +69,7 @@ "'(255) 826-9050',\n", "]" ], - "execution_count": 0, + "execution_count": 16, "outputs": [] }, { @@ -83,16 +84,53 @@ }, { "cell_type": "code", - "metadata": { - "id": "F8n1sN-4XrW3", - "colab_type": "code", - "colab": {} - }, + "execution_count": 17, + "metadata": {}, + "outputs": [], "source": [ - "" + "def no_dups(numbers):\n", + " '''Recursively removes duplicate elements of a list'''\n", + " if numbers == []:\n", + " return []\n", + " else:\n", + " head, *tail = numbers\n", + " numbers = [head] + no_dups(list(filter(lambda x: x != head, tail)))\n", + " return numbers" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "['(765) 368-1506',\n", + " '(285) 608-2448',\n", + " '(255) 826-9050',\n", + " '(554) 994-1517',\n", + " '(596) 336-5508',\n", + " '(511) 821-7870',\n", + " '(410) 665-4447',\n", + " '(821) 642-8987',\n", + " '(311) 799-3883',\n", + " '(935) 875-2054',\n", + " '(464) 788-2397',\n", + " '(650) 684-1437',\n", + " '(812) 816-0881',\n", + " '(885) 407-1719',\n", + " '(943) 769-1061']" + ] + }, + "metadata": {}, + "execution_count": 18 + } ], - "execution_count": 0, - "outputs": [] + "source": [ + "no_dups(numeros_telefone)" + ] } ] -} +} \ No newline at end of file diff --git a/Desafio_06.ipynb b/Desafio_06.ipynb index 4508023..3c71a6b 100644 --- a/Desafio_06.ipynb +++ b/Desafio_06.ipynb @@ -18,7 +18,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.7.9-final" }, "colab": { "name": "Desafio 6.ipynb", @@ -63,9 +63,11 @@ "colab": {} }, "source": [ - "# Seu código" + "# Seu código\n", + "def intersection(seq1, seq2):\n", + " return list(set(seq1) & set(seq2))" ], - "execution_count": 0, + "execution_count": 12, "outputs": [] }, { @@ -76,10 +78,32 @@ "colab": {} }, "source": [ - "" + "a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]\n", + " \n", + "b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]" ], - "execution_count": 0, + "execution_count": 13, "outputs": [] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "[1, 2, 3, 5, 8, 13]" + ] + }, + "metadata": {}, + "execution_count": 14 + } + ], + "source": [ + "intersection(a, b)" + ] } ] -} +} \ No newline at end of file diff --git a/Desafio_07.ipynb b/Desafio_07.ipynb index 5107d99..032909c 100644 --- a/Desafio_07.ipynb +++ b/Desafio_07.ipynb @@ -10,7 +10,8 @@ }, "kernelspec": { "name": "python3", - "display_name": "Python 3" + "display_name": "Python 3", + "language": "python" } }, "cells": [ @@ -58,7 +59,7 @@ " '(228) 976-9699', '(757) 450-9985', '(491) 666-5367',\n", " ]" ], - "execution_count": 0, + "execution_count": 1, "outputs": [] }, { @@ -89,7 +90,7 @@ " '(822) 640-8496', '(227) 389-3685', '(429) 264-7427', \n", " '(397) 845-8267']" ], - "execution_count": 0, + "execution_count": 2, "outputs": [] }, { @@ -104,16 +105,95 @@ }, { "cell_type": "code", - "metadata": { - "id": "_OSrDQ1noh62", - "colab_type": "code", - "colab": {} - }, + "execution_count": 3, + "metadata": {}, + "outputs": [], "source": [ - "" + "outsiders = [ph_num for ph_num in telefones_alunos if ph_num not in entraram_no_grupo]" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "['(873) 810-8267',\n", + " '(300) 303-5462',\n", + " '(941) 225-3869',\n", + " '(294) 430-7720',\n", + " '(835) 955-1498',\n", + " '(897) 932-2512',\n", + " '(640) 427-2597',\n", + " '(856) 338-7094',\n", + " '(641) 367-5279',\n", + " '(964) 710-9625',\n", + " '(403) 343-7705',\n", + " '(797) 649-3653',\n", + " '(757) 450-9985',\n", + " '(491) 666-5367']" + ] + }, + "metadata": {}, + "execution_count": 4 + } ], - "execution_count": 0, - "outputs": [] + "source": [ + "outsiders" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "# solution using sets\n", + "outsiders = set(telefones_alunos) - set(entraram_no_grupo)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "{'(294) 430-7720',\n", + " '(300) 303-5462',\n", + " '(403) 343-7705',\n", + " '(491) 666-5367',\n", + " '(640) 427-2597',\n", + " '(641) 367-5279',\n", + " '(757) 450-9985',\n", + " '(797) 649-3653',\n", + " '(835) 955-1498',\n", + " '(856) 338-7094',\n", + " '(873) 810-8267',\n", + " '(897) 932-2512',\n", + " '(941) 225-3869',\n", + " '(964) 710-9625'}" + ] + }, + "metadata": {}, + "execution_count": 9 + } + ], + "source": [ + "outsiders" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ] -} +} \ No newline at end of file diff --git a/Desafio_08.ipynb b/Desafio_08.ipynb index c6fed05..6187b89 100644 --- a/Desafio_08.ipynb +++ b/Desafio_08.ipynb @@ -18,7 +18,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.7.9-final" }, "colab": { "name": "Desafio 8.ipynb", @@ -59,23 +59,112 @@ "colab": {} }, "source": [ - "# Seu código" + "# import necessary libraries\n", + "import re" ], - "execution_count": 0, + "execution_count": 1, "outputs": [] }, { "cell_type": "code", - "metadata": { - "id": "ZYbqEWBG5nKx", - "colab_type": "code", - "colab": {} - }, + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "def get_words(text):\n", + " '''Returns the 10 longest words of a given list'''\n", + " words = []\n", + " # read file and split into words by ' '\n", + " with open(text, 'r') as f:\n", + " words = f.read().split()\n", + " # clean punctuation\n", + " cl_words = []\n", + " for word in words:\n", + " cl_words.append(re.sub(r'[^\\w\\s]','',word))\n", + " # sort words by length - reversed\n", + " cl_words = sorted(cl_words, key=len, reverse=True)\n", + " \n", + " # check if there are at least 10 words in the list\n", + " if len(cl_words) > 10:\n", + " return cl_words[0:10]\n", + "\n", + " return cl_words" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], "source": [ - "" + " words = get_words('texto.txt')" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "['generalpurpose',\n", + " 'objectoriented',\n", + " 'comprehensive',\n", + " 'intermediate',\n", + " 'interpreted',\n", + " 'programming',\n", + " 'languageIts',\n", + " 'readability',\n", + " 'programmers',\n", + " 'programming']" + ] + }, + "metadata": {}, + "execution_count": 4 + } ], - "execution_count": 0, - "outputs": [] + "source": [ + "words" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "def print_ranking(words):\n", + " print(f'Ranking\\tWord')\n", + " for idx, word in enumerate(words):\n", + " print(f'{idx + 1:>7}\\t{word}')\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Ranking\tWord\n 1\tgeneralpurpose\n 2\tobjectoriented\n 3\tcomprehensive\n 4\tintermediate\n 5\tinterpreted\n 6\tprogramming\n 7\tlanguageIts\n 8\treadability\n 9\tprogrammers\n 10\tprogramming\n" + ] + } + ], + "source": [ + "print_ranking(words)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ] -} +} \ No newline at end of file diff --git a/Desafio_09.ipynb b/Desafio_09.ipynb index 1426b31..10ba6e8 100644 --- a/Desafio_09.ipynb +++ b/Desafio_09.ipynb @@ -18,7 +18,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.7.9-final" }, "colab": { "name": "Desafio 9.ipynb", @@ -57,9 +57,14 @@ "colab": {} }, "source": [ - "# Seu código" + "def sum_multiples_of(n, m, limit):\n", + " '''Returns the num set by limit of multiples of n and m'''\n", + " if n == 0 or m == 0:\n", + " raise Exception(\"Can't divide by zero.\")\n", + " nums = [x for x in range(1, limit + 1)]\n", + " return sum([y for y in nums if y % n == 0 or y % m == 0])" ], - "execution_count": 0, + "execution_count": 22, "outputs": [] }, { @@ -70,10 +75,57 @@ "colab": {} }, "source": [ - "" + "nums = [n for n in range(1, 21)]" ], - "execution_count": 0, + "execution_count": 23, "outputs": [] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]" + ] + }, + "metadata": {}, + "execution_count": 24 + } + ], + "source": [ + "nums" + ] + }, + { + "source": [ + "sum_multiples_of(3, 5, 20)" + ], + "cell_type": "code", + "metadata": {}, + "execution_count": 26, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "98" + ] + }, + "metadata": {}, + "execution_count": 26 + } + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ] -} +} \ No newline at end of file diff --git a/Desafio_10.ipynb b/Desafio_10.ipynb index 0ed40b5..7057972 100644 --- a/Desafio_10.ipynb +++ b/Desafio_10.ipynb @@ -18,7 +18,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.7.9-final" }, "colab": { "name": "Desafio 10.ipynb", @@ -67,9 +67,9 @@ "colab": {} }, "source": [ - "# Seu código" + "sampleList = [11, 45, 8, 23, 14, 12, 78, 45, 89]" ], - "execution_count": 0, + "execution_count": 11, "outputs": [] }, { @@ -80,10 +80,48 @@ "colab": {} }, "source": [ - "" + "import numpy as np \n" ], - "execution_count": 0, + "execution_count": 12, "outputs": [] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "def chunk_reverse(lst, chunk):\n", + " return list(map(lambda ls: list(reversed(ls)), np.array_split(lst, chunk)))\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "[[8, 45, 11], [12, 14, 23], [89, 45, 78]]" + ] + }, + "metadata": {}, + "execution_count": 14 + } + ], + "source": [ + "chunk_reverse(sampleList, 3)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ] } \ No newline at end of file diff --git a/Desafio_11.ipynb b/Desafio_11.ipynb index aa23e34..93d1762 100644 --- a/Desafio_11.ipynb +++ b/Desafio_11.ipynb @@ -18,7 +18,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.7.9-final" }, "colab": { "name": "Desafio 11.ipynb", @@ -61,10 +61,22 @@ }, "source": [ "# Seu código\n", + "\n", + "def is_odd(n):\n", + " return n % 2 == 1\n", + "\n", "def contar_pares_impares(entrada):\n", - " pass" + " '''Counts the number of evens and odds'''\n", + " odd_counter = 0\n", + " even_counter = 0\n", + " for n in entrada:\n", + " if is_odd(n):\n", + " odd_counter += 1\n", + " else:\n", + " even_counter += 1\n", + " return (even_counter, odd_counter)" ], - "execution_count": 0, + "execution_count": 35, "outputs": [] }, { @@ -75,10 +87,21 @@ "colab": {} }, "source": [ - "" + "contar_pares_impares([6, 2, 7, -5, 8, -4])" ], - "execution_count": 0, - "outputs": [] + "execution_count": 36, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "(4, 2)" + ] + }, + "metadata": {}, + "execution_count": 36 + } + ] }, { "cell_type": "code", @@ -87,9 +110,7 @@ "colab_type": "code", "colab": {} }, - "source": [ - "" - ], + "source": [], "execution_count": 0, "outputs": [] }, @@ -115,7 +136,7 @@ "\n", "# Se nenhuma mensagem for impressa abaixo, significa que a função está implementada corretamente" ], - "execution_count": 0, + "execution_count": 37, "outputs": [] }, { @@ -125,9 +146,7 @@ "colab_type": "code", "colab": {} }, - "source": [ - "" - ], + "source": [], "execution_count": 0, "outputs": [] }, @@ -138,9 +157,7 @@ "colab_type": "code", "colab": {} }, - "source": [ - "" - ], + "source": [], "execution_count": 0, "outputs": [] } diff --git a/Desafio_12.ipynb b/Desafio_12.ipynb index 0ebd52a..14ab755 100644 --- a/Desafio_12.ipynb +++ b/Desafio_12.ipynb @@ -18,7 +18,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.7.9-final" }, "colab": { "name": "Desafio 12.ipynb", @@ -74,23 +74,81 @@ "colab": {} }, "source": [ - "# Seu código" + "def password_check(pwd):\n", + " '''Checks for password validity'''\n", + " if 6 <= len(pwd) <= 16:\n", + " if (at_least_one(is_digit, pwd) and \n", + " at_least_one(is_letter, pwd) and \n", + " at_least_one(is_spec_chars, pwd)):\n", + " return f'{pwd} - Valid Password.'\n", + " else:\n", + " return f'{pwd} - Invalid Password.'\n", + "\n", + "# helper functions\n", + "def is_letter(c):\n", + " return c.isalpha()\n", + "\n", + "def is_digit(n):\n", + " return n.isdigit()\n", + "\n", + "def is_spec_chars(c):\n", + " spec_chars = ['$', '#', '@']\n", + " return c in spec_chars\n", + "\n", + "def at_least_one(f, lst):\n", + " return any(list(map(f, lst)))\n", + "\n", + " " ], - "execution_count": 0, + "execution_count": 80, "outputs": [] }, { "cell_type": "code", - "metadata": { - "id": "n8F01NzD9uHm", - "colab_type": "code", - "colab": {} - }, + "execution_count": 81, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'1234 - Invalid Password.'" + ] + }, + "metadata": {}, + "execution_count": 81 + } + ], "source": [ - "" + "password_check('1234')" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "metadata": {}, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'Qw#1234 - Valid Password.'" + ] + }, + "metadata": {}, + "execution_count": 82 + } ], - "execution_count": 0, - "outputs": [] + "source": [ + "password_check('Qw#1234')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ] } \ No newline at end of file