diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb index ee9444d..981d3fe 100644 --- a/Python-ifed.ipynb +++ b/Python-ifed.ipynb @@ -62,15 +62,16 @@ "### Describe what each of the following means\n", "\n", "#### Production\n", - "(Insert answer here)\n", + "The software running on production servers to handle live users and data of the intended audience. \n", "#### Clean \n", - "(Insert answer here)\n", + "readable, simple, and concise. A characteristic of production quality code that is crucial for collaboration and maintainability in software development.\n", + "\n", "#### Modular\n", - "(Insert answer here)\n", + " logically broken up into functions and modules. Also an important characteristic of production quality code that makes your code more organized, efficient, and reusable.\n", "#### Module\n", - "(Insert answer here)\n", + "a file. Modules allow code to be reused by encapsulating them into files that can be imported into other files.\n", "#### Refactoring code\n", - "(Insert answer here)" + "Code refactoring is defined as the process of restructuring computer code without changing or adding to its external behavior and functionality." ] }, { @@ -93,9 +94,214 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Seasoncitydateteam 1team 2toss winnertoss decisionresultdl appliedwinnerwin by runswin by wicketsplayer of matchvenueumpire 1umpire 2
id
1IPL-2017Hyderabad05-04-2017Sunrisers HyderabadRoyal Challengers BangaloreRoyal Challengers Bangalorefieldnormal0Sunrisers Hyderabad350Yuvraj SinghRajiv Gandhi International Stadium, UppalAY DandekarNJ Llong
2IPL-2017Pune06-04-2017Mumbai IndiansRising Pune SupergiantRising Pune Supergiantfieldnormal0Rising Pune Supergiant07SPD SmithMaharashtra Cricket Association StadiumA Nand KishoreS Ravi
3IPL-2017Rajkot07-04-2017Gujarat LionsKolkata Knight RidersKolkata Knight Ridersfieldnormal0Kolkata Knight Riders010CA LynnSaurashtra Cricket Association StadiumNitin MenonCK Nandan
4IPL-2017Indore08-04-2017Rising Pune SupergiantKings XI PunjabKings XI Punjabfieldnormal0Kings XI Punjab06GJ MaxwellHolkar Cricket StadiumAK ChaudharyC Shamshuddin
5IPL-2017Bangalore08-04-2017Royal Challengers BangaloreDelhi DaredevilsRoyal Challengers Bangalorebatnormal0Royal Challengers Bangalore150KM JadhavM Chinnaswamy StadiumNaNNaN
\n", + "
" + ], + "text/plain": [ + " Season city date team 1 \\\n", + "id \n", + "1 IPL-2017 Hyderabad 05-04-2017 Sunrisers Hyderabad \n", + "2 IPL-2017 Pune 06-04-2017 Mumbai Indians \n", + "3 IPL-2017 Rajkot 07-04-2017 Gujarat Lions \n", + "4 IPL-2017 Indore 08-04-2017 Rising Pune Supergiant \n", + "5 IPL-2017 Bangalore 08-04-2017 Royal Challengers Bangalore \n", + "\n", + " team 2 toss winner toss decision \\\n", + "id \n", + "1 Royal Challengers Bangalore Royal Challengers Bangalore field \n", + "2 Rising Pune Supergiant Rising Pune Supergiant field \n", + "3 Kolkata Knight Riders Kolkata Knight Riders field \n", + "4 Kings XI Punjab Kings XI Punjab field \n", + "5 Delhi Daredevils Royal Challengers Bangalore bat \n", + "\n", + " result dl applied winner win by runs \\\n", + "id \n", + "1 normal 0 Sunrisers Hyderabad 35 \n", + "2 normal 0 Rising Pune Supergiant 0 \n", + "3 normal 0 Kolkata Knight Riders 0 \n", + "4 normal 0 Kings XI Punjab 0 \n", + "5 normal 0 Royal Challengers Bangalore 15 \n", + "\n", + " win by wickets player of match venue \\\n", + "id \n", + "1 0 Yuvraj Singh Rajiv Gandhi International Stadium, Uppal \n", + "2 7 SPD Smith Maharashtra Cricket Association Stadium \n", + "3 10 CA Lynn Saurashtra Cricket Association Stadium \n", + "4 6 GJ Maxwell Holkar Cricket Stadium \n", + "5 0 KM Jadhav M Chinnaswamy Stadium \n", + "\n", + " umpire 1 umpire 2 \n", + "id \n", + "1 AY Dandekar NJ Llong \n", + "2 A Nand Kishore S Ravi \n", + "3 Nitin Menon CK Nandan \n", + "4 AK Chaudhary C Shamshuddin \n", + "5 NaN NaN " + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import pandas as pd\n", "df = pd.read_csv('matches.csv', sep=',')\n", @@ -113,9 +319,214 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Seasoncitydateteam_1team_2toss_winnertoss decisionresultdl_appliedwinnerwin_by_runswin_by_wicketsplayer_of_matchvenueumpire_1umpire_2
id
1IPL-2017Hyderabad05-04-2017Sunrisers HyderabadRoyal Challengers BangaloreRoyal Challengers Bangalorefieldnormal0Sunrisers Hyderabad350Yuvraj SinghRajiv Gandhi International Stadium, UppalAY DandekarNJ Llong
2IPL-2017Pune06-04-2017Mumbai IndiansRising Pune SupergiantRising Pune Supergiantfieldnormal0Rising Pune Supergiant07SPD SmithMaharashtra Cricket Association StadiumA Nand KishoreS Ravi
3IPL-2017Rajkot07-04-2017Gujarat LionsKolkata Knight RidersKolkata Knight Ridersfieldnormal0Kolkata Knight Riders010CA LynnSaurashtra Cricket Association StadiumNitin MenonCK Nandan
4IPL-2017Indore08-04-2017Rising Pune SupergiantKings XI PunjabKings XI Punjabfieldnormal0Kings XI Punjab06GJ MaxwellHolkar Cricket StadiumAK ChaudharyC Shamshuddin
5IPL-2017Bangalore08-04-2017Royal Challengers BangaloreDelhi DaredevilsRoyal Challengers Bangalorebatnormal0Royal Challengers Bangalore150KM JadhavM Chinnaswamy StadiumNaNNaN
\n", + "
" + ], + "text/plain": [ + " Season city date team_1 \\\n", + "id \n", + "1 IPL-2017 Hyderabad 05-04-2017 Sunrisers Hyderabad \n", + "2 IPL-2017 Pune 06-04-2017 Mumbai Indians \n", + "3 IPL-2017 Rajkot 07-04-2017 Gujarat Lions \n", + "4 IPL-2017 Indore 08-04-2017 Rising Pune Supergiant \n", + "5 IPL-2017 Bangalore 08-04-2017 Royal Challengers Bangalore \n", + "\n", + " team_2 toss_winner toss decision \\\n", + "id \n", + "1 Royal Challengers Bangalore Royal Challengers Bangalore field \n", + "2 Rising Pune Supergiant Rising Pune Supergiant field \n", + "3 Kolkata Knight Riders Kolkata Knight Riders field \n", + "4 Kings XI Punjab Kings XI Punjab field \n", + "5 Delhi Daredevils Royal Challengers Bangalore bat \n", + "\n", + " result dl_applied winner win_by_runs \\\n", + "id \n", + "1 normal 0 Sunrisers Hyderabad 35 \n", + "2 normal 0 Rising Pune Supergiant 0 \n", + "3 normal 0 Kolkata Knight Riders 0 \n", + "4 normal 0 Kings XI Punjab 0 \n", + "5 normal 0 Royal Challengers Bangalore 15 \n", + "\n", + " win_by_wickets player_of_match venue \\\n", + "id \n", + "1 0 Yuvraj Singh Rajiv Gandhi International Stadium, Uppal \n", + "2 7 SPD Smith Maharashtra Cricket Association Stadium \n", + "3 10 CA Lynn Saurashtra Cricket Association Stadium \n", + "4 6 GJ Maxwell Holkar Cricket Stadium \n", + "5 0 KM Jadhav M Chinnaswamy Stadium \n", + "\n", + " umpire_1 umpire_2 \n", + "id \n", + "1 AY Dandekar NJ Llong \n", + "2 A Nand Kishore S Ravi \n", + "3 Nitin Menon CK Nandan \n", + "4 AK Chaudhary C Shamshuddin \n", + "5 NaN NaN " + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "new_df = df.rename(columns={'team 1': 'team_1',\n", " 'team 2': 'team_2',\n", @@ -139,9 +550,214 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Seasoncitydateteam_1team 2toss_winnertoss_decisionresultdl_appliedwinnerwin_by_runswin by wicketsplayer of matchvenueumpire 1umpire 2
id
1IPL-2017Hyderabad05-04-2017Sunrisers HyderabadRoyal Challengers BangaloreRoyal Challengers Bangalorefieldnormal0Sunrisers Hyderabad350Yuvraj SinghRajiv Gandhi International Stadium, UppalAY DandekarNJ Llong
2IPL-2017Pune06-04-2017Mumbai IndiansRising Pune SupergiantRising Pune Supergiantfieldnormal0Rising Pune Supergiant07SPD SmithMaharashtra Cricket Association StadiumA Nand KishoreS Ravi
3IPL-2017Rajkot07-04-2017Gujarat LionsKolkata Knight RidersKolkata Knight Ridersfieldnormal0Kolkata Knight Riders010CA LynnSaurashtra Cricket Association StadiumNitin MenonCK Nandan
4IPL-2017Indore08-04-2017Rising Pune SupergiantKings XI PunjabKings XI Punjabfieldnormal0Kings XI Punjab06GJ MaxwellHolkar Cricket StadiumAK ChaudharyC Shamshuddin
5IPL-2017Bangalore08-04-2017Royal Challengers BangaloreDelhi DaredevilsRoyal Challengers Bangalorebatnormal0Royal Challengers Bangalore150KM JadhavM Chinnaswamy StadiumNaNNaN
\n", + "
" + ], + "text/plain": [ + " Season city date team_1 \\\n", + "id \n", + "1 IPL-2017 Hyderabad 05-04-2017 Sunrisers Hyderabad \n", + "2 IPL-2017 Pune 06-04-2017 Mumbai Indians \n", + "3 IPL-2017 Rajkot 07-04-2017 Gujarat Lions \n", + "4 IPL-2017 Indore 08-04-2017 Rising Pune Supergiant \n", + "5 IPL-2017 Bangalore 08-04-2017 Royal Challengers Bangalore \n", + "\n", + " team 2 toss_winner toss_decision \\\n", + "id \n", + "1 Royal Challengers Bangalore Royal Challengers Bangalore field \n", + "2 Rising Pune Supergiant Rising Pune Supergiant field \n", + "3 Kolkata Knight Riders Kolkata Knight Riders field \n", + "4 Kings XI Punjab Kings XI Punjab field \n", + "5 Delhi Daredevils Royal Challengers Bangalore bat \n", + "\n", + " result dl_applied winner win_by_runs \\\n", + "id \n", + "1 normal 0 Sunrisers Hyderabad 35 \n", + "2 normal 0 Rising Pune Supergiant 0 \n", + "3 normal 0 Kolkata Knight Riders 0 \n", + "4 normal 0 Kings XI Punjab 0 \n", + "5 normal 0 Royal Challengers Bangalore 15 \n", + "\n", + " win by wickets player of match venue \\\n", + "id \n", + "1 0 Yuvraj Singh Rajiv Gandhi International Stadium, Uppal \n", + "2 7 SPD Smith Maharashtra Cricket Association Stadium \n", + "3 10 CA Lynn Saurashtra Cricket Association Stadium \n", + "4 6 GJ Maxwell Holkar Cricket Stadium \n", + "5 0 KM Jadhav M Chinnaswamy Stadium \n", + "\n", + " umpire 1 umpire 2 \n", + "id \n", + "1 AY Dandekar NJ Llong \n", + "2 A Nand Kishore S Ravi \n", + "3 Nitin Menon CK Nandan \n", + "4 AK Chaudhary C Shamshuddin \n", + "5 NaN NaN " + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "labels = list(df.columns)\n", "labels[0] = labels[0].replace(' ', '_')\n", @@ -167,11 +783,220 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Seasoncitydateteam_1team_2toss_winnertoss_decisionresultdl_appliedwinnerwin_by_runswin_by_wicketsplayer_of_matchvenueumpire_1umpire_2
id
1IPL-2017Hyderabad05-04-2017Sunrisers HyderabadRoyal Challengers BangaloreRoyal Challengers Bangalorefieldnormal0Sunrisers Hyderabad350Yuvraj SinghRajiv Gandhi International Stadium, UppalAY DandekarNJ Llong
2IPL-2017Pune06-04-2017Mumbai IndiansRising Pune SupergiantRising Pune Supergiantfieldnormal0Rising Pune Supergiant07SPD SmithMaharashtra Cricket Association StadiumA Nand KishoreS Ravi
3IPL-2017Rajkot07-04-2017Gujarat LionsKolkata Knight RidersKolkata Knight Ridersfieldnormal0Kolkata Knight Riders010CA LynnSaurashtra Cricket Association StadiumNitin MenonCK Nandan
4IPL-2017Indore08-04-2017Rising Pune SupergiantKings XI PunjabKings XI Punjabfieldnormal0Kings XI Punjab06GJ MaxwellHolkar Cricket StadiumAK ChaudharyC Shamshuddin
5IPL-2017Bangalore08-04-2017Royal Challengers BangaloreDelhi DaredevilsRoyal Challengers Bangalorebatnormal0Royal Challengers Bangalore150KM JadhavM Chinnaswamy StadiumNaNNaN
\n", + "
" + ], + "text/plain": [ + " Season city date team_1 \\\n", + "id \n", + "1 IPL-2017 Hyderabad 05-04-2017 Sunrisers Hyderabad \n", + "2 IPL-2017 Pune 06-04-2017 Mumbai Indians \n", + "3 IPL-2017 Rajkot 07-04-2017 Gujarat Lions \n", + "4 IPL-2017 Indore 08-04-2017 Rising Pune Supergiant \n", + "5 IPL-2017 Bangalore 08-04-2017 Royal Challengers Bangalore \n", + "\n", + " team_2 toss_winner toss_decision \\\n", + "id \n", + "1 Royal Challengers Bangalore Royal Challengers Bangalore field \n", + "2 Rising Pune Supergiant Rising Pune Supergiant field \n", + "3 Kolkata Knight Riders Kolkata Knight Riders field \n", + "4 Kings XI Punjab Kings XI Punjab field \n", + "5 Delhi Daredevils Royal Challengers Bangalore bat \n", + "\n", + " result dl_applied winner win_by_runs \\\n", + "id \n", + "1 normal 0 Sunrisers Hyderabad 35 \n", + "2 normal 0 Rising Pune Supergiant 0 \n", + "3 normal 0 Kolkata Knight Riders 0 \n", + "4 normal 0 Kings XI Punjab 0 \n", + "5 normal 0 Royal Challengers Bangalore 15 \n", + "\n", + " win_by_wickets player_of_match venue \\\n", + "id \n", + "1 0 Yuvraj Singh Rajiv Gandhi International Stadium, Uppal \n", + "2 7 SPD Smith Maharashtra Cricket Association Stadium \n", + "3 10 CA Lynn Saurashtra Cricket Association Stadium \n", + "4 6 GJ Maxwell Holkar Cricket Stadium \n", + "5 0 KM Jadhav M Chinnaswamy Stadium \n", + "\n", + " umpire_1 umpire_2 \n", + "id \n", + "1 AY Dandekar NJ Llong \n", + "2 A Nand Kishore S Ravi \n", + "3 Nitin Menon CK Nandan \n", + "4 AK Chaudhary C Shamshuddin \n", + "5 NaN NaN " + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Insert your solution here" + "labels = list(df.columns)\n", + "for i in range(len(labels)):\n", + " labels[i] = labels[i].replace(' ','_')\n", + "df.columns = labels\n", + "df.head()" ] }, { @@ -208,7 +1033,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 61, "metadata": {}, "outputs": [], "source": [ @@ -219,7 +1044,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 62, "metadata": {}, "outputs": [], "source": [ @@ -233,9 +1058,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "96\n", + "Duration: 7.4446024894714355 seconds\n" + ] + } + ], "source": [ "start = time.time()\n", "verified_elements = []\n", @@ -257,14 +1091,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 68, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "96\n", + "Duration: 0.09533023834228516 seconds\n" + ] + } + ], "source": [ - "# Insert answer here\n", + "start = time.time()\n", "\n", - "print(len(verified_elements))\n", - "print('Duration: {} seconds'.format(time.time() - start))" + "x = np.intersect1d(np.array(subset_elements), np.array(all_elements)) \n", + "\n", + "print(len(x))\n", + "print(f'Duration: {time.time() - start} seconds')" ] }, { @@ -276,13 +1121,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 67, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "96\n", + "Duration: 0.0049016475677490234 seconds\n" + ] + } + ], "source": [ - "# Insert answer here\n", - "\n", - "print(len(verified_elements))\n", + "start = time.time()\n", + "c=set(subset_elements).intersection(all_elements)\n", + "print(len(c))\n", "print('Duration: {} seconds'.format(time.time() - start))" ] }, @@ -330,9 +1184,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[1m============================= test session starts ==============================\u001b[0m\n", + "platform linux -- Python 3.8.5, pytest-6.2.1, py-1.10.0, pluggy-0.13.1\n", + "rootdir: /home/ubuntu/Python-ifed\n", + "plugins: anyio-2.0.2\n", + "collected 4 items \u001b[0m\n", + "\n", + "test_nearest_square.py \u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m [100%]\u001b[0m\n", + "\n", + "\u001b[32m============================== \u001b[32m\u001b[1m4 passed\u001b[0m\u001b[32m in 0.01s\u001b[0m\u001b[32m ===============================\u001b[0m\n" + ] + } + ], "source": [ "! pytest test_nearest_square.py" ] @@ -386,11 +1256,27 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "electric\n" + ] + } + ], "source": [ - "# Insert your code here" + "import requests, json\n", + "response = requests.get('https://pokeapi.co/api/v2/pokemon/25')\n", + "text = json.dumps(response.json(), sort_keys=True, indent=4)\n", + "json_object = json.loads(text)\n", + "pairs = json_object.items()\n", + "a = json_object['types']\n", + "b = a[0]\n", + "c = b['type']\n", + "print(c['name'])" ] }, { @@ -404,11 +1290,31 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ground\n" + ] + } + ], "source": [ - "# Insert your code here" + "import requests, json\n", + "response = requests.get('https://pokeapi.co/api/v2/pokemon/25')\n", + "text = json.dumps(response.json(), sort_keys=True, indent=4)\n", + "json_object = json.loads(text)\n", + "pairs = json_object.items()\n", + "a = json_object['name']\n", + "#print(a)\n", + "response = requests.get('https://pokeapi.co/api/v2/type/13')\n", + "text = json.dumps(response.json(), sort_keys=True, indent=4)\n", + "json_object = json.loads(text)\n", + "a= json_object['damage_relations']\n", + "b = a['double_damage_from']\n", + "print(b[0]['name'])" ] }, { @@ -420,11 +1326,40 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Type: ground\n", + "sandshrew\n", + "sandslash\n", + "nidoqueen\n", + "nidoking\n", + "diglett\n" + ] + } + ], "source": [ - "# Insert your code here" + "import requests, json\n", + "\n", + "response = requests.get('https://pokeapi.co/api/v2/type/13')\n", + "text = json.dumps(response.json(), sort_keys=True, indent=4)\n", + "json_object = json.loads(text)\n", + "a= json_object['damage_relations']\n", + "b = a['double_damage_from']\n", + "print(\"Type: \",b[0]['name'])\n", + "\n", + "pokemon = requests.get('https://pokeapi.co/api/v2/type/5')\n", + "name = json.dumps(pokemon.json(), sort_keys=True, indent=4)\n", + "json_object2 = json.loads(name)\n", + "for i in range(5):\n", + " a = json_object2['pokemon']\n", + " b = a[i]\n", + " c = b['pokemon']\n", + " print(c['name'])" ] }, { @@ -438,7 +1373,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -446,13 +1381,14 @@ "output_type": "stream", "text": [ "\u001b[1m============================= test session starts ==============================\u001b[0m\n", - "platform darwin -- Python 3.8.5, pytest-6.2.1, py-1.10.0, pluggy-0.13.1\n", - "rootdir: /Users/abhijitramesh/development/Python-ifed\n", + "platform linux -- Python 3.8.5, pytest-6.2.1, py-1.10.0, pluggy-0.13.1\n", + "rootdir: /home/ubuntu/Python-ifed\n", + "plugins: anyio-2.0.2\n", "collected 4 items \u001b[0m\n", "\n", "test_abilities.py \u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m [100%]\u001b[0m\n", "\n", - "\u001b[32m============================== \u001b[32m\u001b[1m4 passed\u001b[0m\u001b[32m in 2.75s\u001b[0m\u001b[32m ===============================\u001b[0m\n" + "\u001b[32m============================== \u001b[32m\u001b[1m4 passed\u001b[0m\u001b[32m in 4.21s\u001b[0m\u001b[32m ===============================\u001b[0m\n" ] } ], @@ -515,9 +1451,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.9" + "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..9de6ac3 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# Python-ifed \ No newline at end of file diff --git a/__pycache__/ability.cpython-38.pyc b/__pycache__/ability.cpython-38.pyc new file mode 100644 index 0000000..eb51857 Binary files /dev/null and b/__pycache__/ability.cpython-38.pyc differ diff --git a/__pycache__/nearest_square.cpython-38.pyc b/__pycache__/nearest_square.cpython-38.pyc new file mode 100644 index 0000000..e932cb9 Binary files /dev/null and b/__pycache__/nearest_square.cpython-38.pyc differ diff --git a/__pycache__/test_abilities.cpython-38-pytest-6.2.1.pyc b/__pycache__/test_abilities.cpython-38-pytest-6.2.1.pyc new file mode 100644 index 0000000..b6448be Binary files /dev/null and b/__pycache__/test_abilities.cpython-38-pytest-6.2.1.pyc differ diff --git a/__pycache__/test_nearest_square.cpython-38-pytest-6.2.1.pyc b/__pycache__/test_nearest_square.cpython-38-pytest-6.2.1.pyc new file mode 100644 index 0000000..e7b8298 Binary files /dev/null and b/__pycache__/test_nearest_square.cpython-38-pytest-6.2.1.pyc differ diff --git a/ability.py b/ability.py new file mode 100644 index 0000000..2155a7c --- /dev/null +++ b/ability.py @@ -0,0 +1,18 @@ +import requests, json + +def ability(name): + response = requests.get('https://pokeapi.co/api/v2/pokemon/' + str(name)) + text = json.dumps(response.json(), indent=4) + + json_object = json.loads(text) + + + A = [] + for i in range(len(json_object['abilities'])): + a= json_object['abilities'] + b = a[i] + c = b['ability'] + final = c['name'] + A.append(final) + + return A \ No newline at end of file diff --git a/nearest_square.py b/nearest_square.py new file mode 100644 index 0000000..8fe0895 --- /dev/null +++ b/nearest_square.py @@ -0,0 +1,15 @@ +def nearest_square(limit): + if limit < 0: + return 0 + + while limit > 3: + i = 2 + while i <= limit//2: + square = i*i + if square == limit: + return square + else: + i += 1 + limit -= 1 + return 1 + \ No newline at end of file diff --git a/step4.py b/step4.py new file mode 100644 index 0000000..95b8f50 --- /dev/null +++ b/step4.py @@ -0,0 +1,47 @@ +import time +import pandas as pd +import numpy as np + +with open('subset_elemets.txt') as f: + subset_elements = f.read().split('\n') + +with open('all_elements.txt') as f: + all_elements = f.read().split('\n') + +def Number_elements(file1,file2): + """Defined a function named Number_elements.This also contains intersect1d function from numpy module. + ##parameters + file1,file2 + + ##Returns: + returns the total number of elements present in both the files. + """ + start = time.time() + + verified_element = np.intersect1d(np.array(file1), np.array(file2)) + + print(len(verified_element)) + print(f'Duration: {time.time() - start} seconds') + +Number_elements(subset_elements, all_elements) + +Method_one(subset_elements, all_elements) + +# This is using datastructures + +def Method_two(file1,file2): + """Defined a function named Method_two.This also uses the built in function intersection to find out the elements that are present as common in both the files. + ##parameters + file1,file2 + + ##Returns: + returns the total number of elements present in both the files. + """ + start = time.time() + + verified_element=set(file1).intersection(file2) + + print(len(verified_element)) + print('Duration: {} seconds'.format(time.time() - start)) + +Method_two(subset_elements, all_elements)