diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index 2e59d77..b01959a 100755 --- a/your-code/challenge-1.ipynb +++ b/your-code/challenge-1.ipynb @@ -15,11 +15,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "# Your code here\n", + "tup = 'I'," ] }, { @@ -33,11 +34,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "('I',)" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "tup\n" ] }, { @@ -55,13 +68,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# Your code here\n", - "\n", - "# Your explanation here\n" + "tup = ('I', 'r', 'n', 'h', 'a', 'c', 'k')\n", + "# Your explanation here\n", + "# tuples doesn't allow to add element since they are inmmutables" ] }, { @@ -79,13 +93,15 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "# Your code here\n", + "tup = ('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n", "\n", - "# Your explanation here\n" + "# Your explanation here\n", + "# Yes, since we are not changing any element in the tuple, we are Re-assigning to the variable tup a new tuple " ] }, { @@ -103,11 +119,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n')\n", + "('h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "tup1 = tup[0:4]\n", + "tup2 = tup[-4:]\n", + "print(tup1)\n", + "print(tup2)" ] }, { @@ -121,11 +150,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n", + "yes\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "tup3 = tup1 + tup2\n", + "print(tup3)\n", + "\n", + "if tup3 == tup:\n", + " print('yes')\n", + "else:\n", + " print('no')" ] }, { @@ -137,11 +182,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n", + "4\n", + "8\n", + "yes\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "print(len(tup1))\n", + "print(len(tup2))\n", + "counts = len(tup1) + len(tup2)\n", + "print(counts)\n", + "\n", + "if counts == len(tup3):\n", + " print('yes')\n", + "else:\n", + " print('false')" ] }, { @@ -153,11 +218,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 36, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'h'" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "tup3[4]" ] }, { @@ -177,11 +254,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n", + "True\n", + "False\n", + "False\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "letters = ['a', 'b', 'c', 'd', 'e']\n", + "\n", + "for letter in letters:\n", + " if letter in tup3:\n", + " print(True)\n", + " else:\n", + " print(False)" ] }, { @@ -195,12 +291,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 38, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "count = 0\n", + "\n", + "for letter in letters:\n", + " if letter in tup3:\n", + " count += 1\n", + "print(count)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -219,7 +336,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.8.8" } }, "nbformat": 4, diff --git a/your-code/challenge-2.ipynb b/your-code/challenge-2.ipynb index 41d6911..d76e59a 100755 --- a/your-code/challenge-2.ipynb +++ b/your-code/challenge-2.ipynb @@ -13,7 +13,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -38,11 +38,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[98, 87, 51, 66, 0, 58, 84, 24, 2, 27, 49, 12, 68, 15, 34, 32, 75, 9, 38, 91, 80, 82, 16, 56, 13, 69, 95, 52, 88, 11, 76, 57, 71, 54, 37, 59, 8, 33, 45, 78, 21, 93, 86, 14, 39, 6, 28, 42, 90, 1, 99, 48, 85, 70, 29, 44, 77, 96, 3, 26, 36, 7, 74, 92, 79, 25, 55, 73, 30, 63, 40, 65, 22, 64, 20, 35, 10, 67, 4, 17]\n" + ] + } + ], "source": [ - "# Your code here\n" + "\n", + "s=list(range(100)) #Cada valor es un entero que cae entre 0 y 100\n", + "sample_list_1=random.sample(s,80) #generando los 80 números aleatorios (sin repetición)\n", + "print(sample_list_1)\n" ] }, { @@ -54,11 +65,28 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20, 21, 22, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36, 37, 38, 39, 40, 42, 44, 45, 48, 49, 51, 52, 54, 55, 56, 57, 58, 59, 63, 64, 65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78, 79, 80, 82, 84, 85, 86, 87, 88, 90, 91, 92, 93, 95, 96, 98, 99}\n", + "Tamaño: 80\n", + "Su longitud sigue siendo 80 . No hay repeticiones.\n" + ] + } + ], + "source": [ + "set1=set(sample_list_1)\n", + "print(set1)\n", + "print('Tamaño:',len(set1))\n", + "\n", + "if len(set1)==len(sample_list_1):\n", + " print('Su longitud sigue siendo ',len(sample_list_1),'. No hay repeticiones.')\n", + "else:\n", + " print('Su longitud cambió. Los sets no toman repeticiones.')" ] }, { @@ -77,11 +105,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Tamaño: 80\n", + "[30, 37, 91, 55, 59, 93, 40, 66, 49, 64, 64, 2, 85, 58, 65, 57, 67, 44, 10, 48, 40, 73, 0, 37, 14, 11, 77, 11, 67, 88, 34, 51, 4, 65, 90, 9, 77, 2, 96, 0, 49, 54, 11, 93, 56, 55, 39, 28, 58, 33, 4, 38, 75, 9, 11, 32, 33, 1, 68, 84, 44, 13, 38, 54, 51, 30, 13, 15, 20, 8, 40, 15, 10, 45, 24, 36, 2, 32, 68, 75]\n" + ] + } + ], "source": [ - "# Your code here\n" + "sample_list_2=random.choices(sample_list_1,k=80) #generando los 80 números aleatorios (con repetición)\n", + "print('Tamaño:',len(sample_list_2))\n", + "print(sample_list_2)" ] }, { @@ -93,11 +132,28 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 1, 2, 4, 8, 9, 10, 11, 13, 14, 15, 20, 24, 28, 30, 32, 33, 34, 36, 37, 38, 39, 40, 44, 45, 48, 49, 51, 54, 55, 56, 57, 58, 59, 64, 65, 66, 67, 68, 73, 75, 77, 84, 85, 88, 90, 91, 93, 96}\n", + "Tamaño: 49\n", + "Su longitud cambió. Los sets no toman repeticiones.\n" + ] + } + ], + "source": [ + "set2=set(sample_list_2)\n", + "print(set2)\n", + "print('Tamaño:',len(set2))\n", + "\n", + "if len(set2)==len(sample_list_2):\n", + " print('Su longitud sigue siendo ',len(sample_list_2))\n", + "else:\n", + " print('Su longitud cambió. Los sets no toman repeticiones.')\n" ] }, { @@ -109,11 +165,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Tamaño: 31\n", + "{3, 6, 7, 12, 16, 17, 21, 22, 25, 26, 27, 29, 35, 42, 52, 63, 69, 70, 71, 74, 76, 78, 79, 80, 82, 86, 87, 92, 95, 98, 99}\n" + ] + } + ], "source": [ - "# Your code here\n" + "set3=set1-set2\n", + "print('Tamaño: ',len(set3))\n", + "print(set3)" ] }, { @@ -125,11 +192,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Tamaño: 0\n", + "set()\n" + ] + } + ], "source": [ - "# Your code here\n" + "set4=set2.difference(set1)\n", + "print('Tamaño: ',len(set4))\n", + "print(set4)\n" ] }, { @@ -141,11 +219,71 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{0,\n", + " 1,\n", + " 2,\n", + " 4,\n", + " 8,\n", + " 9,\n", + " 10,\n", + " 11,\n", + " 13,\n", + " 14,\n", + " 15,\n", + " 20,\n", + " 24,\n", + " 28,\n", + " 30,\n", + " 32,\n", + " 33,\n", + " 34,\n", + " 36,\n", + " 37,\n", + " 38,\n", + " 39,\n", + " 40,\n", + " 44,\n", + " 45,\n", + " 48,\n", + " 49,\n", + " 51,\n", + " 54,\n", + " 55,\n", + " 56,\n", + " 57,\n", + " 58,\n", + " 59,\n", + " 64,\n", + " 65,\n", + " 66,\n", + " 67,\n", + " 68,\n", + " 73,\n", + " 75,\n", + " 77,\n", + " 84,\n", + " 85,\n", + " 88,\n", + " 90,\n", + " 91,\n", + " 93,\n", + " 96}" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set5=set1.intersection(set2)\n", + "set5\n" ] }, { @@ -165,11 +303,24 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "a=len(set1)+len(set2)-len(set5)\n", + "b=len(set3)+len(set4)+len(set5)\n", + "\n", + "if a==b: \n", + " print (True)\n", + "#Usé lo siguiente: como se trata de conjuntos, lo relacioné como que la unión de conjuntos es la suma de ambos menos la intersección " ] }, { @@ -181,11 +332,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "set6=set()\n" ] }, { @@ -197,11 +348,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20, 21, 22, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36, 37, 38, 39, 40, 42, 44, 45, 48, 49, 51, 52, 54, 55, 56, 57, 58, 59, 63, 64, 65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78, 79, 80, 82, 84, 85, 86, 87, 88, 90, 91, 92, 93, 95, 96, 98, 99}\n" + ] + } + ], "source": [ - "# Your code here\n" + "set6=set3.union(set5)\n", + "print(set6)\n", + "\n" ] }, { @@ -213,11 +374,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "set1==set6\n" ] }, { @@ -229,11 +401,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "¿Está set1 dentro de set2?: True\n", + "¿Está set1 dentro de set3?: True\n" + ] + } + ], "source": [ - "# Your code here\n" + "a=set2.issubset(set1)\n", + "print('¿Está set1 dentro de set2?: ',a)\n", + "b=set3.issubset(set1)\n", + "print('¿Está set1 dentro de set3?: ',b)" ] }, { @@ -247,11 +431,28 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "True\n" + ] + } + ], + "source": [ + "set345=set3.union(set4,set5)\n", + "set12345=set345.union(set1,set2)\n", + "\n", + "#PRIMERA OPCIÓN\n", + "set12=set1.union(set2) #esto es para comparar si los valores agregados son iguales a lo que ya se tenía\n", + "print(set12==set345)\n", + "\n", + "#OTRA OPCIÓN:\n", + "print(set345.issubset(set12)) #ver si set12 es subconjunto de set345\n" ] }, { @@ -263,11 +464,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n" + ] + } + ], + "source": [ + "set1_modif=set1.pop() #Este método devuelve un elemento aleatorio del conjunto y lo elimina del mismo\n", + "\n", + "print(set1_modif)" ] }, { @@ -283,12 +494,48 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{2, 3, 4, 6, 7, 8, 10, 12, 13, 14, 15, 16, 17, 20, 22, 24, 25, 26, 27, 28, 30, 32, 33, 34, 35, 36, 37, 38, 40, 42, 44, 45, 48, 52, 54, 55, 56, 57, 58, 63, 64, 65, 66, 67, 68, 70, 73, 74, 75, 76, 77, 78, 80, 82, 84, 85, 86, 87, 88, 90, 92, 93, 95, 96, 98}\n" + ] + } + ], + "source": [ + "\n", + "list_to_remove = [1, 9, 11, 19, 21, 29, 31, 39, 41, 49, 51, 59, 61, 69, 71, 79, 81, 89, 91, 99]\n", + "a=set(list_to_remove)\n", + "set1_nvo=set1-a\n", + "print(set1_nvo)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20, 21, 22, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36, 37, 38, 39, 40, 42, 44, 45, 48, 49, 51, 52, 54, 55, 56, 57, 58, 59, 63, 64, 65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78, 79, 80, 82, 84, 85, 86, 87, 88, 90, 91, 92, 93, 95, 96, 98, 99}\n" + ] + } + ], "source": [ - "# Your code here\n" + "print(set1)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -307,7 +554,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.8.8" } }, "nbformat": 4, diff --git a/your-code/challenge-3.ipynb b/your-code/challenge-3.ipynb index 7ab8ea5..5850aef 100755 --- a/your-code/challenge-3.ipynb +++ b/your-code/challenge-3.ipynb @@ -15,13 +15,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 53, "metadata": {}, "outputs": [], "source": [ "word_freq = {'love': 25, 'conversation': 1, 'every': 6, \"we're\": 1, 'plate': 1, 'sour': 1, 'jukebox': 1, 'now': 11, 'taxi': 1, 'fast': 1, 'bag': 1, 'man': 1, 'push': 3, 'baby': 14, 'going': 1, 'you': 16, \"don't\": 2, 'one': 1, 'mind': 2, 'backseat': 1, 'friends': 1, 'then': 3, 'know': 2, 'take': 1, 'play': 1, 'okay': 1, 'so': 2, 'begin': 1, 'start': 2, 'over': 1, 'body': 17, 'boy': 2, 'just': 1, 'we': 7, 'are': 1, 'girl': 2, 'tell': 1, 'singing': 2, 'drinking': 1, 'put': 3, 'our': 1, 'where': 1, \"i'll\": 1, 'all': 1, \"isn't\": 1, 'make': 1, 'lover': 1, 'get': 1, 'radio': 1, 'give': 1, \"i'm\": 23, 'like': 10, 'can': 1, 'doing': 2, 'with': 22, 'club': 1, 'come': 37, 'it': 1, 'somebody': 2, 'handmade': 2, 'out': 1, 'new': 6, 'room': 3, 'chance': 1, 'follow': 6, 'in': 27, 'may': 2, 'brand': 6, 'that': 2, 'magnet': 3, 'up': 3, 'first': 1, 'and': 23, 'pull': 3, 'of': 6, 'table': 1, 'much': 2, 'last': 3, 'i': 6, 'thrifty': 1, 'grab': 2, 'was': 2, 'driver': 1, 'slow': 1, 'dance': 1, 'the': 18, 'say': 2, 'trust': 1, 'family': 1, 'week': 1, 'date': 1, 'me': 10, 'do': 3, 'waist': 2, 'smell': 3, 'day': 6, 'although': 3, 'your': 21, 'leave': 1, 'want': 2, \"let's\": 2, 'lead': 6, 'at': 1, 'hand': 1, 'how': 1, 'talk': 4, 'not': 2, 'eat': 1, 'falling': 3, 'about': 1, 'story': 1, 'sweet': 1, 'best': 1, 'crazy': 2, 'let': 1, 'too': 5, 'van': 1, 'shots': 1, 'go': 2, 'to': 2, 'a': 8, 'my': 33, 'is': 5, 'place': 1, 'find': 1, 'shape': 6, 'on': 40, 'kiss': 1, 'were': 3, 'night': 3, 'heart': 3, 'for': 3, 'discovering': 6, 'something': 6, 'be': 16, 'bedsheets': 3, 'fill': 2, 'hours': 2, 'stop': 1, 'bar': 1}" ] }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "140" + ] + }, + "execution_count": 54, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(word_freq)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -49,11 +69,394 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 55, + "metadata": {}, + "outputs": [], + "source": [ + "keys1 = []\n", + "for k in word_freq.keys():\n", + " keys1.append(k)" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": {}, + "outputs": [], + "source": [ + "keys1 = sorted(keys1)" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['a',\n", + " 'about',\n", + " 'all',\n", + " 'although',\n", + " 'and',\n", + " 'are',\n", + " 'at',\n", + " 'baby',\n", + " 'backseat',\n", + " 'bag',\n", + " 'bar',\n", + " 'be',\n", + " 'bedsheets',\n", + " 'begin',\n", + " 'best',\n", + " 'body',\n", + " 'boy',\n", + " 'brand',\n", + " 'can',\n", + " 'chance',\n", + " 'club',\n", + " 'come',\n", + " 'conversation',\n", + " 'crazy',\n", + " 'dance',\n", + " 'date',\n", + " 'day',\n", + " 'discovering',\n", + " 'do',\n", + " 'doing',\n", + " \"don't\",\n", + " 'drinking',\n", + " 'driver',\n", + " 'eat',\n", + " 'every',\n", + " 'falling',\n", + " 'family',\n", + " 'fast',\n", + " 'fill',\n", + " 'find',\n", + " 'first',\n", + " 'follow',\n", + " 'for',\n", + " 'friends',\n", + " 'get',\n", + " 'girl',\n", + " 'give',\n", + " 'go',\n", + " 'going',\n", + " 'grab',\n", + " 'hand',\n", + " 'handmade',\n", + " 'heart',\n", + " 'hours',\n", + " 'how',\n", + " 'i',\n", + " \"i'll\",\n", + " \"i'm\",\n", + " 'in',\n", + " 'is',\n", + " \"isn't\",\n", + " 'it',\n", + " 'jukebox',\n", + " 'just',\n", + " 'kiss',\n", + " 'know',\n", + " 'last',\n", + " 'lead',\n", + " 'leave',\n", + " 'let',\n", + " \"let's\",\n", + " 'like',\n", + " 'love',\n", + " 'lover',\n", + " 'magnet',\n", + " 'make',\n", + " 'man',\n", + " 'may',\n", + " 'me',\n", + " 'mind',\n", + " 'much',\n", + " 'my',\n", + " 'new',\n", + " 'night',\n", + " 'not',\n", + " 'now',\n", + " 'of',\n", + " 'okay',\n", + " 'on',\n", + " 'one',\n", + " 'our',\n", + " 'out',\n", + " 'over',\n", + " 'place',\n", + " 'plate',\n", + " 'play',\n", + " 'pull',\n", + " 'push',\n", + " 'put',\n", + " 'radio',\n", + " 'room',\n", + " 'say',\n", + " 'shape',\n", + " 'shots',\n", + " 'singing',\n", + " 'slow',\n", + " 'smell',\n", + " 'so',\n", + " 'somebody',\n", + " 'something',\n", + " 'sour',\n", + " 'start',\n", + " 'stop',\n", + " 'story',\n", + " 'sweet',\n", + " 'table',\n", + " 'take',\n", + " 'talk',\n", + " 'taxi',\n", + " 'tell',\n", + " 'that',\n", + " 'the',\n", + " 'then',\n", + " 'thrifty',\n", + " 'to',\n", + " 'too',\n", + " 'trust',\n", + " 'up',\n", + " 'van',\n", + " 'waist',\n", + " 'want',\n", + " 'was',\n", + " 'we',\n", + " \"we're\",\n", + " 'week',\n", + " 'were',\n", + " 'where',\n", + " 'with',\n", + " 'you',\n", + " 'your']" + ] + }, + "execution_count": 57, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "keys1" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict_keys(['love', 'conversation', 'every', \"we're\", 'plate', 'sour', 'jukebox', 'now', 'taxi', 'fast', 'bag', 'man', 'push', 'baby', 'going', 'you', \"don't\", 'one', 'mind', 'backseat', 'friends', 'then', 'know', 'take', 'play', 'okay', 'so', 'begin', 'start', 'over', 'body', 'boy', 'just', 'we', 'are', 'girl', 'tell', 'singing', 'drinking', 'put', 'our', 'where', \"i'll\", 'all', \"isn't\", 'make', 'lover', 'get', 'radio', 'give', \"i'm\", 'like', 'can', 'doing', 'with', 'club', 'come', 'it', 'somebody', 'handmade', 'out', 'new', 'room', 'chance', 'follow', 'in', 'may', 'brand', 'that', 'magnet', 'up', 'first', 'and', 'pull', 'of', 'table', 'much', 'last', 'i', 'thrifty', 'grab', 'was', 'driver', 'slow', 'dance', 'the', 'say', 'trust', 'family', 'week', 'date', 'me', 'do', 'waist', 'smell', 'day', 'although', 'your', 'leave', 'want', \"let's\", 'lead', 'at', 'hand', 'how', 'talk', 'not', 'eat', 'falling', 'about', 'story', 'sweet', 'best', 'crazy', 'let', 'too', 'van', 'shots', 'go', 'to', 'a', 'my', 'is', 'place', 'find', 'shape', 'on', 'kiss', 'were', 'night', 'heart', 'for', 'discovering', 'something', 'be', 'bedsheets', 'fill', 'hours', 'stop', 'bar'])" + ] + }, + "execution_count": 58, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "word_freq.keys()" + ] + }, + { + "cell_type": "code", + "execution_count": 59, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "word_freq2 = {}\n", + "\n", + "for i in keys1:\n", + " for k, v in word_freq.items():\n", + " if i == k:\n", + " word_freq2[k] = v" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'a': 8,\n", + " 'about': 1,\n", + " 'all': 1,\n", + " 'although': 3,\n", + " 'and': 23,\n", + " 'are': 1,\n", + " 'at': 1,\n", + " 'baby': 14,\n", + " 'backseat': 1,\n", + " 'bag': 1,\n", + " 'bar': 1,\n", + " 'be': 16,\n", + " 'bedsheets': 3,\n", + " 'begin': 1,\n", + " 'best': 1,\n", + " 'body': 17,\n", + " 'boy': 2,\n", + " 'brand': 6,\n", + " 'can': 1,\n", + " 'chance': 1,\n", + " 'club': 1,\n", + " 'come': 37,\n", + " 'conversation': 1,\n", + " 'crazy': 2,\n", + " 'dance': 1,\n", + " 'date': 1,\n", + " 'day': 6,\n", + " 'discovering': 6,\n", + " 'do': 3,\n", + " 'doing': 2,\n", + " \"don't\": 2,\n", + " 'drinking': 1,\n", + " 'driver': 1,\n", + " 'eat': 1,\n", + " 'every': 6,\n", + " 'falling': 3,\n", + " 'family': 1,\n", + " 'fast': 1,\n", + " 'fill': 2,\n", + " 'find': 1,\n", + " 'first': 1,\n", + " 'follow': 6,\n", + " 'for': 3,\n", + " 'friends': 1,\n", + " 'get': 1,\n", + " 'girl': 2,\n", + " 'give': 1,\n", + " 'go': 2,\n", + " 'going': 1,\n", + " 'grab': 2,\n", + " 'hand': 1,\n", + " 'handmade': 2,\n", + " 'heart': 3,\n", + " 'hours': 2,\n", + " 'how': 1,\n", + " 'i': 6,\n", + " \"i'll\": 1,\n", + " \"i'm\": 23,\n", + " 'in': 27,\n", + " 'is': 5,\n", + " \"isn't\": 1,\n", + " 'it': 1,\n", + " 'jukebox': 1,\n", + " 'just': 1,\n", + " 'kiss': 1,\n", + " 'know': 2,\n", + " 'last': 3,\n", + " 'lead': 6,\n", + " 'leave': 1,\n", + " 'let': 1,\n", + " \"let's\": 2,\n", + " 'like': 10,\n", + " 'love': 25,\n", + " 'lover': 1,\n", + " 'magnet': 3,\n", + " 'make': 1,\n", + " 'man': 1,\n", + " 'may': 2,\n", + " 'me': 10,\n", + " 'mind': 2,\n", + " 'much': 2,\n", + " 'my': 33,\n", + " 'new': 6,\n", + " 'night': 3,\n", + " 'not': 2,\n", + " 'now': 11,\n", + " 'of': 6,\n", + " 'okay': 1,\n", + " 'on': 40,\n", + " 'one': 1,\n", + " 'our': 1,\n", + " 'out': 1,\n", + " 'over': 1,\n", + " 'place': 1,\n", + " 'plate': 1,\n", + " 'play': 1,\n", + " 'pull': 3,\n", + " 'push': 3,\n", + " 'put': 3,\n", + " 'radio': 1,\n", + " 'room': 3,\n", + " 'say': 2,\n", + " 'shape': 6,\n", + " 'shots': 1,\n", + " 'singing': 2,\n", + " 'slow': 1,\n", + " 'smell': 3,\n", + " 'so': 2,\n", + " 'somebody': 2,\n", + " 'something': 6,\n", + " 'sour': 1,\n", + " 'start': 2,\n", + " 'stop': 1,\n", + " 'story': 1,\n", + " 'sweet': 1,\n", + " 'table': 1,\n", + " 'take': 1,\n", + " 'talk': 4,\n", + " 'taxi': 1,\n", + " 'tell': 1,\n", + " 'that': 2,\n", + " 'the': 18,\n", + " 'then': 3,\n", + " 'thrifty': 1,\n", + " 'to': 2,\n", + " 'too': 5,\n", + " 'trust': 1,\n", + " 'up': 3,\n", + " 'van': 1,\n", + " 'waist': 2,\n", + " 'want': 2,\n", + " 'was': 2,\n", + " 'we': 7,\n", + " \"we're\": 1,\n", + " 'week': 1,\n", + " 'were': 3,\n", + " 'where': 1,\n", + " 'with': 22,\n", + " 'you': 16,\n", + " 'your': 21}" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "word_freq2" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "140" + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(word_freq2)" ] }, { @@ -90,11 +493,192 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[('conversation', 1), (\"we're\", 1), ('plate', 1), ('sour', 1), ('jukebox', 1), ('taxi', 1), ('fast', 1), ('bag', 1), ('man', 1), ('going', 1), ('one', 1), ('backseat', 1), ('friends', 1), ('take', 1), ('play', 1), ('okay', 1), ('begin', 1), ('over', 1), ('just', 1), ('are', 1), ('tell', 1), ('drinking', 1), ('our', 1), ('where', 1), (\"i'll\", 1), ('all', 1), (\"isn't\", 1), ('make', 1), ('lover', 1), ('get', 1), ('radio', 1), ('give', 1), ('can', 1), ('club', 1), ('it', 1), ('out', 1), ('chance', 1), ('first', 1), ('table', 1), ('thrifty', 1), ('driver', 1), ('slow', 1), ('dance', 1), ('trust', 1), ('family', 1), ('week', 1), ('date', 1), ('leave', 1), ('at', 1), ('hand', 1), ('how', 1), ('eat', 1), ('about', 1), ('story', 1), ('sweet', 1), ('best', 1), ('let', 1), ('van', 1), ('shots', 1), ('place', 1), ('find', 1), ('kiss', 1), ('stop', 1), ('bar', 1), (\"don't\", 2), ('mind', 2), ('know', 2), ('so', 2), ('start', 2), ('boy', 2), ('girl', 2), ('singing', 2), ('doing', 2), ('somebody', 2), ('handmade', 2), ('may', 2), ('that', 2), ('much', 2), ('grab', 2), ('was', 2), ('say', 2), ('waist', 2), ('want', 2), (\"let's\", 2), ('not', 2), ('crazy', 2), ('go', 2), ('to', 2), ('fill', 2), ('hours', 2), ('push', 3), ('then', 3), ('put', 3), ('room', 3), ('magnet', 3), ('up', 3), ('pull', 3), ('last', 3), ('do', 3), ('smell', 3), ('although', 3), ('falling', 3), ('were', 3), ('night', 3), ('heart', 3), ('for', 3), ('bedsheets', 3), ('talk', 4), ('too', 5), ('is', 5), ('every', 6), ('new', 6), ('follow', 6), ('brand', 6), ('of', 6), ('i', 6), ('day', 6), ('lead', 6), ('shape', 6), ('discovering', 6), ('something', 6), ('we', 7), ('a', 8), ('like', 10), ('me', 10), ('now', 11), ('baby', 14), ('you', 16), ('be', 16), ('body', 17), ('the', 18), ('your', 21), ('with', 22), (\"i'm\", 23), ('and', 23), ('love', 25), ('in', 27), ('my', 33), ('come', 37), ('on', 40)]\n" + ] + } + ], + "source": [ + "# Your code here\n", + "import operator\n", + "sorted_tups = sorted(word_freq.items(), key=operator.itemgetter(1))\n", + "print(sorted_tups)" + ] + }, + { + "cell_type": "code", + "execution_count": 64, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "word_freq2 = {}\n", + "for i in sorted_tups:\n", + " word_freq2[i[0]] = i[1] " + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'conversation': 1,\n", + " \"we're\": 1,\n", + " 'plate': 1,\n", + " 'sour': 1,\n", + " 'jukebox': 1,\n", + " 'taxi': 1,\n", + " 'fast': 1,\n", + " 'bag': 1,\n", + " 'man': 1,\n", + " 'going': 1,\n", + " 'one': 1,\n", + " 'backseat': 1,\n", + " 'friends': 1,\n", + " 'take': 1,\n", + " 'play': 1,\n", + " 'okay': 1,\n", + " 'begin': 1,\n", + " 'over': 1,\n", + " 'just': 1,\n", + " 'are': 1,\n", + " 'tell': 1,\n", + " 'drinking': 1,\n", + " 'our': 1,\n", + " 'where': 1,\n", + " \"i'll\": 1,\n", + " 'all': 1,\n", + " \"isn't\": 1,\n", + " 'make': 1,\n", + " 'lover': 1,\n", + " 'get': 1,\n", + " 'radio': 1,\n", + " 'give': 1,\n", + " 'can': 1,\n", + " 'club': 1,\n", + " 'it': 1,\n", + " 'out': 1,\n", + " 'chance': 1,\n", + " 'first': 1,\n", + " 'table': 1,\n", + " 'thrifty': 1,\n", + " 'driver': 1,\n", + " 'slow': 1,\n", + " 'dance': 1,\n", + " 'trust': 1,\n", + " 'family': 1,\n", + " 'week': 1,\n", + " 'date': 1,\n", + " 'leave': 1,\n", + " 'at': 1,\n", + " 'hand': 1,\n", + " 'how': 1,\n", + " 'eat': 1,\n", + " 'about': 1,\n", + " 'story': 1,\n", + " 'sweet': 1,\n", + " 'best': 1,\n", + " 'let': 1,\n", + " 'van': 1,\n", + " 'shots': 1,\n", + " 'place': 1,\n", + " 'find': 1,\n", + " 'kiss': 1,\n", + " 'stop': 1,\n", + " 'bar': 1,\n", + " \"don't\": 2,\n", + " 'mind': 2,\n", + " 'know': 2,\n", + " 'so': 2,\n", + " 'start': 2,\n", + " 'boy': 2,\n", + " 'girl': 2,\n", + " 'singing': 2,\n", + " 'doing': 2,\n", + " 'somebody': 2,\n", + " 'handmade': 2,\n", + " 'may': 2,\n", + " 'that': 2,\n", + " 'much': 2,\n", + " 'grab': 2,\n", + " 'was': 2,\n", + " 'say': 2,\n", + " 'waist': 2,\n", + " 'want': 2,\n", + " \"let's\": 2,\n", + " 'not': 2,\n", + " 'crazy': 2,\n", + " 'go': 2,\n", + " 'to': 2,\n", + " 'fill': 2,\n", + " 'hours': 2,\n", + " 'push': 3,\n", + " 'then': 3,\n", + " 'put': 3,\n", + " 'room': 3,\n", + " 'magnet': 3,\n", + " 'up': 3,\n", + " 'pull': 3,\n", + " 'last': 3,\n", + " 'do': 3,\n", + " 'smell': 3,\n", + " 'although': 3,\n", + " 'falling': 3,\n", + " 'were': 3,\n", + " 'night': 3,\n", + " 'heart': 3,\n", + " 'for': 3,\n", + " 'bedsheets': 3,\n", + " 'talk': 4,\n", + " 'too': 5,\n", + " 'is': 5,\n", + " 'every': 6,\n", + " 'new': 6,\n", + " 'follow': 6,\n", + " 'brand': 6,\n", + " 'of': 6,\n", + " 'i': 6,\n", + " 'day': 6,\n", + " 'lead': 6,\n", + " 'shape': 6,\n", + " 'discovering': 6,\n", + " 'something': 6,\n", + " 'we': 7,\n", + " 'a': 8,\n", + " 'like': 10,\n", + " 'me': 10,\n", + " 'now': 11,\n", + " 'baby': 14,\n", + " 'you': 16,\n", + " 'be': 16,\n", + " 'body': 17,\n", + " 'the': 18,\n", + " 'your': 21,\n", + " 'with': 22,\n", + " \"i'm\": 23,\n", + " 'and': 23,\n", + " 'love': 25,\n", + " 'in': 27,\n", + " 'my': 33,\n", + " 'come': 37,\n", + " 'on': 40}" + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "word_freq2" ] }, { @@ -110,7 +694,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 66, "metadata": {}, "outputs": [], "source": [ @@ -132,11 +716,129 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 67, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "# Your code here\n", + "df = pd.DataFrame(word_freq.items(), columns = ['word', 'freq'])" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
| \n", + " | word | \n", + "freq | \n", + "
|---|---|---|
| 0 | \n", + "love | \n", + "25 | \n", + "
| 1 | \n", + "conversation | \n", + "1 | \n", + "
| 2 | \n", + "every | \n", + "6 | \n", + "
| 3 | \n", + "we're | \n", + "1 | \n", + "
| 4 | \n", + "plate | \n", + "1 | \n", + "
| ... | \n", + "... | \n", + "... | \n", + "
| 135 | \n", + "bedsheets | \n", + "3 | \n", + "
| 136 | \n", + "fill | \n", + "2 | \n", + "
| 137 | \n", + "hours | \n", + "2 | \n", + "
| 138 | \n", + "stop | \n", + "1 | \n", + "
| 139 | \n", + "bar | \n", + "1 | \n", + "
140 rows × 2 columns
\n", + "| \n", + " | word | \n", + "freq | \n", + "
|---|---|---|
| 120 | \n", + "a | \n", + "8 | \n", + "
| 109 | \n", + "about | \n", + "1 | \n", + "
| 43 | \n", + "all | \n", + "1 | \n", + "
| 96 | \n", + "although | \n", + "3 | \n", + "
| 72 | \n", + "and | \n", + "23 | \n", + "
| ... | \n", + "... | \n", + "... | \n", + "
| 128 | \n", + "were | \n", + "3 | \n", + "
| 41 | \n", + "where | \n", + "1 | \n", + "
| 54 | \n", + "with | \n", + "22 | \n", + "
| 15 | \n", + "you | \n", + "16 | \n", + "
| 97 | \n", + "your | \n", + "21 | \n", + "
140 rows × 2 columns
\n", + "| \n", + " | word | \n", + "freq | \n", + "
|---|---|---|
| 139 | \n", + "bar | \n", + "1 | \n", + "
| 114 | \n", + "let | \n", + "1 | \n", + "
| 116 | \n", + "van | \n", + "1 | \n", + "
| 60 | \n", + "out | \n", + "1 | \n", + "
| 57 | \n", + "it | \n", + "1 | \n", + "
| ... | \n", + "... | \n", + "... | \n", + "
| 0 | \n", + "love | \n", + "25 | \n", + "
| 65 | \n", + "in | \n", + "27 | \n", + "
| 121 | \n", + "my | \n", + "33 | \n", + "
| 56 | \n", + "come | \n", + "37 | \n", + "
| 126 | \n", + "on | \n", + "40 | \n", + "
140 rows × 2 columns
\n", + "