diff --git a/HW_2.ipynb b/HW_2.ipynb index 6b85c7c..624fc93 100644 --- a/HW_2.ipynb +++ b/HW_2.ipynb @@ -220,11 +220,11 @@ { "cell_type": "code", "metadata": { - "id": "v5NWpk8sx9BT", - "outputId": "90f440eb-096f-429d-d61e-333e1eb833e9", "colab": { "base_uri": "https://localhost:8080/" - } + }, + "id": "v5NWpk8sx9BT", + "outputId": "90f440eb-096f-429d-d61e-333e1eb833e9" }, "source": [ "from google.colab import drive\n", @@ -244,11 +244,11 @@ { "cell_type": "code", "metadata": { - "id": "VjmQ5hWOx_QO", - "outputId": "24f4f47e-d1a7-445a-d77f-8bda7ba5dd22", "colab": { "base_uri": "https://localhost:8080/" - } + }, + "id": "VjmQ5hWOx_QO", + "outputId": "24f4f47e-d1a7-445a-d77f-8bda7ba5dd22" }, "source": [ "import json\n", @@ -311,11 +311,11 @@ { "cell_type": "code", "metadata": { - "id": "XpdIMnqxyCa7", - "outputId": "55e1b0fa-e7c2-4151-b715-2f86cfbc12c1", "colab": { "base_uri": "https://localhost:8080/" - } + }, + "id": "XpdIMnqxyCa7", + "outputId": "55e1b0fa-e7c2-4151-b715-2f86cfbc12c1" }, "source": [ "# Creating a dataset directory\n", @@ -343,12 +343,12 @@ { "cell_type": "code", "metadata": { - "id": "Ifgyk4SVy0gg", - "outputId": "24e480aa-e923-487a-8847-4edcf56df3fc", "colab": { "base_uri": "https://localhost:8080/", "height": 204 - } + }, + "id": "Ifgyk4SVy0gg", + "outputId": "24e480aa-e923-487a-8847-4edcf56df3fc" }, "source": [ "\n", @@ -446,14 +446,24 @@ "id": "gYIoTJNIifX8" }, "source": [ - "hero_dic = {}\n", + "hero_1_2_dic = {}\n", "new_df = {'hero1':[] , 'hero2':[]}\n", "for index, row1 in df.iterrows():\n", " hero1 = row1['hero1']\n", " hero2 = row1['hero2']\n", - " if \"hero1\" not in hero_dic:\n", - " hero_dic[hero1]=[]\n", - " hero_dic[hero1].append(hero2)\n", + " if hero1 not in hero_1_2_dic:\n", + " hero_1_2_dic[hero1]=[]\n", + " hero_1_2_dic[hero1].append(hero2)\n", + "\n", + "\n", + "hero_2_1_dic = {}\n", + "#new_df = {'hero1':[] , 'hero2':[]}\n", + "for index, row1 in df.iterrows():\n", + " hero1 = row1['hero1']\n", + " hero2 = row1['hero2']\n", + " if hero2 not in hero_2_1_dic:\n", + " hero_2_1_dic[hero2]=[]\n", + " hero_2_1_dic[hero2].append(hero1)\n", " \n", " # for index, row2 in df.copy().iterrows():\n", " # copy_hero1 = row2['hero1']\n", @@ -463,9 +473,35 @@ " #new_df['hero1'].append(hero1)\n", " " ], - "execution_count": null, + "execution_count": 15, "outputs": [] }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "7BICMJM011PE", + "outputId": "33c224bf-fd7f-4dde-fea0-cd596bef6b96" + }, + "source": [ + " for item in hero_1_2_dic.items():\n", + " print(item)\n", + " break\n", + "\n" + ], + "execution_count": 16, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "('LITTLE, ABNER', ['PRINCESS ZANDA'])\n" + ] + } + ] + }, { "cell_type": "markdown", "metadata": {