diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb
index ee9444d..9749e60 100644
--- a/Python-ifed.ipynb
+++ b/Python-ifed.ipynb
@@ -27,8 +27,6 @@
]
},
{
- "cell_type": "markdown",
- "metadata": {},
"source": [
"## Step 0\n",
"\n",
@@ -47,7 +45,11 @@
"https://www.atlassian.com/git\n",
"\n",
"https://www.tutorialspoint.com/git/git_basic_concepts.htm"
- ]
+ ],
+ "cell_type": "code",
+ "metadata": {},
+ "execution_count": null,
+ "outputs": []
},
{
"cell_type": "markdown",
@@ -62,15 +64,15 @@
"### Describe what each of the following means\n",
"\n",
"#### Production\n",
- "(Insert answer here)\n",
+ "The code that is reliable and is the final version and which is available to the client is called Production Code.\n",
"#### Clean \n",
- "(Insert answer here)\n",
+ "The code that is easily readable and understandable to both the author and anyone who has access to the code is called Clean Code.\n",
"#### Modular\n",
- "(Insert answer here)\n",
+ "The code which can be divided into independent blocks which when combined produces a meaningful code is called Modular Code.\n",
"#### Module\n",
- "(Insert answer here)\n",
+ "The individual piece of code is called a Module.\n",
"#### Refactoring code\n",
- "(Insert answer here)"
+ "The process of restructuring or simplifying the design of a code without changing its logic or behaviour is called Refactoring Code."
]
},
{
@@ -93,9 +95,59 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 6,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "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 "
+ ],
+ "text/html": "
\n\n
\n \n \n | \n Season | \n city | \n date | \n team 1 | \n team 2 | \n toss winner | \n toss decision | \n result | \n dl applied | \n winner | \n win by runs | \n win by wickets | \n player of match | \n venue | \n umpire 1 | \n umpire 2 | \n
\n \n | id | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n
\n \n \n \n | 1 | \n IPL-2017 | \n Hyderabad | \n 05-04-2017 | \n Sunrisers Hyderabad | \n Royal Challengers Bangalore | \n Royal Challengers Bangalore | \n field | \n normal | \n 0 | \n Sunrisers Hyderabad | \n 35 | \n 0 | \n Yuvraj Singh | \n Rajiv Gandhi International Stadium, Uppal | \n AY Dandekar | \n NJ Llong | \n
\n \n | 2 | \n IPL-2017 | \n Pune | \n 06-04-2017 | \n Mumbai Indians | \n Rising Pune Supergiant | \n Rising Pune Supergiant | \n field | \n normal | \n 0 | \n Rising Pune Supergiant | \n 0 | \n 7 | \n SPD Smith | \n Maharashtra Cricket Association Stadium | \n A Nand Kishore | \n S Ravi | \n
\n \n | 3 | \n IPL-2017 | \n Rajkot | \n 07-04-2017 | \n Gujarat Lions | \n Kolkata Knight Riders | \n Kolkata Knight Riders | \n field | \n normal | \n 0 | \n Kolkata Knight Riders | \n 0 | \n 10 | \n CA Lynn | \n Saurashtra Cricket Association Stadium | \n Nitin Menon | \n CK Nandan | \n
\n \n | 4 | \n IPL-2017 | \n Indore | \n 08-04-2017 | \n Rising Pune Supergiant | \n Kings XI Punjab | \n Kings XI Punjab | \n field | \n normal | \n 0 | \n Kings XI Punjab | \n 0 | \n 6 | \n GJ Maxwell | \n Holkar Cricket Stadium | \n AK Chaudhary | \n C Shamshuddin | \n
\n \n | 5 | \n IPL-2017 | \n Bangalore | \n 08-04-2017 | \n Royal Challengers Bangalore | \n Delhi Daredevils | \n Royal Challengers Bangalore | \n bat | \n normal | \n 0 | \n Royal Challengers Bangalore | \n 15 | \n 0 | \n KM Jadhav | \n M Chinnaswamy Stadium | \n NaN | \n NaN | \n
\n \n
\n
"
+ },
+ "metadata": {},
+ "execution_count": 6
+ }
+ ],
"source": [
"import pandas as pd\n",
"df = pd.read_csv('matches.csv', sep=',')\n",
@@ -113,9 +165,59 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 31,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "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 "
+ ],
+ "text/html": "\n\n
\n \n \n | \n Season | \n city | \n date | \n team_1 | \n team_2 | \n toss_winner | \n toss_decision | \n result | \n dl_applied | \n winner | \n win_by_runs | \n win_by_wickets | \n player_of_match | \n venue | \n umpire_1 | \n umpire_2 | \n
\n \n | id | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n
\n \n \n \n | 1 | \n IPL-2017 | \n Hyderabad | \n 05-04-2017 | \n Sunrisers Hyderabad | \n Royal Challengers Bangalore | \n Royal Challengers Bangalore | \n field | \n normal | \n 0 | \n Sunrisers Hyderabad | \n 35 | \n 0 | \n Yuvraj Singh | \n Rajiv Gandhi International Stadium, Uppal | \n AY Dandekar | \n NJ Llong | \n
\n \n | 2 | \n IPL-2017 | \n Pune | \n 06-04-2017 | \n Mumbai Indians | \n Rising Pune Supergiant | \n Rising Pune Supergiant | \n field | \n normal | \n 0 | \n Rising Pune Supergiant | \n 0 | \n 7 | \n SPD Smith | \n Maharashtra Cricket Association Stadium | \n A Nand Kishore | \n S Ravi | \n
\n \n | 3 | \n IPL-2017 | \n Rajkot | \n 07-04-2017 | \n Gujarat Lions | \n Kolkata Knight Riders | \n Kolkata Knight Riders | \n field | \n normal | \n 0 | \n Kolkata Knight Riders | \n 0 | \n 10 | \n CA Lynn | \n Saurashtra Cricket Association Stadium | \n Nitin Menon | \n CK Nandan | \n
\n \n | 4 | \n IPL-2017 | \n Indore | \n 08-04-2017 | \n Rising Pune Supergiant | \n Kings XI Punjab | \n Kings XI Punjab | \n field | \n normal | \n 0 | \n Kings XI Punjab | \n 0 | \n 6 | \n GJ Maxwell | \n Holkar Cricket Stadium | \n AK Chaudhary | \n C Shamshuddin | \n
\n \n | 5 | \n IPL-2017 | \n Bangalore | \n 08-04-2017 | \n Royal Challengers Bangalore | \n Delhi Daredevils | \n Royal Challengers Bangalore | \n bat | \n normal | \n 0 | \n Royal Challengers Bangalore | \n 15 | \n 0 | \n KM Jadhav | \n M Chinnaswamy Stadium | \n NaN | \n NaN | \n
\n \n
\n
"
+ },
+ "metadata": {},
+ "execution_count": 31
+ }
+ ],
"source": [
"new_df = df.rename(columns={'team 1': 'team_1',\n",
" 'team 2': 'team_2',\n",
@@ -139,9 +241,59 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 30,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "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 "
+ ],
+ "text/html": "\n\n
\n \n \n | \n Season | \n city | \n date | \n team_1 | \n team_2 | \n toss_winner | \n toss_decision | \n result | \n dl_applied | \n winner | \n win_by_runs | \n win_by_wickets | \n player_of_match | \n venue | \n umpire_1 | \n umpire_2 | \n
\n \n | id | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n
\n \n \n \n | 1 | \n IPL-2017 | \n Hyderabad | \n 05-04-2017 | \n Sunrisers Hyderabad | \n Royal Challengers Bangalore | \n Royal Challengers Bangalore | \n field | \n normal | \n 0 | \n Sunrisers Hyderabad | \n 35 | \n 0 | \n Yuvraj Singh | \n Rajiv Gandhi International Stadium, Uppal | \n AY Dandekar | \n NJ Llong | \n
\n \n | 2 | \n IPL-2017 | \n Pune | \n 06-04-2017 | \n Mumbai Indians | \n Rising Pune Supergiant | \n Rising Pune Supergiant | \n field | \n normal | \n 0 | \n Rising Pune Supergiant | \n 0 | \n 7 | \n SPD Smith | \n Maharashtra Cricket Association Stadium | \n A Nand Kishore | \n S Ravi | \n
\n \n | 3 | \n IPL-2017 | \n Rajkot | \n 07-04-2017 | \n Gujarat Lions | \n Kolkata Knight Riders | \n Kolkata Knight Riders | \n field | \n normal | \n 0 | \n Kolkata Knight Riders | \n 0 | \n 10 | \n CA Lynn | \n Saurashtra Cricket Association Stadium | \n Nitin Menon | \n CK Nandan | \n
\n \n | 4 | \n IPL-2017 | \n Indore | \n 08-04-2017 | \n Rising Pune Supergiant | \n Kings XI Punjab | \n Kings XI Punjab | \n field | \n normal | \n 0 | \n Kings XI Punjab | \n 0 | \n 6 | \n GJ Maxwell | \n Holkar Cricket Stadium | \n AK Chaudhary | \n C Shamshuddin | \n
\n \n | 5 | \n IPL-2017 | \n Bangalore | \n 08-04-2017 | \n Royal Challengers Bangalore | \n Delhi Daredevils | \n Royal Challengers Bangalore | \n bat | \n normal | \n 0 | \n Royal Challengers Bangalore | \n 15 | \n 0 | \n KM Jadhav | \n M Chinnaswamy Stadium | \n NaN | \n NaN | \n
\n \n
\n
"
+ },
+ "metadata": {},
+ "execution_count": 30
+ }
+ ],
"source": [
"labels = list(df.columns)\n",
"labels[0] = labels[0].replace(' ', '_')\n",
@@ -167,11 +319,63 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 8,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "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 "
+ ],
+ "text/html": "\n\n
\n \n \n | \n Season | \n city | \n date | \n team_1 | \n team_2 | \n toss_winner | \n toss_decision | \n result | \n dl_applied | \n winner | \n win_by_runs | \n win_by_wickets | \n player_of_match | \n venue | \n umpire_1 | \n umpire_2 | \n
\n \n | id | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n | \n
\n \n \n \n | 1 | \n IPL-2017 | \n Hyderabad | \n 05-04-2017 | \n Sunrisers Hyderabad | \n Royal Challengers Bangalore | \n Royal Challengers Bangalore | \n field | \n normal | \n 0 | \n Sunrisers Hyderabad | \n 35 | \n 0 | \n Yuvraj Singh | \n Rajiv Gandhi International Stadium, Uppal | \n AY Dandekar | \n NJ Llong | \n
\n \n | 2 | \n IPL-2017 | \n Pune | \n 06-04-2017 | \n Mumbai Indians | \n Rising Pune Supergiant | \n Rising Pune Supergiant | \n field | \n normal | \n 0 | \n Rising Pune Supergiant | \n 0 | \n 7 | \n SPD Smith | \n Maharashtra Cricket Association Stadium | \n A Nand Kishore | \n S Ravi | \n
\n \n | 3 | \n IPL-2017 | \n Rajkot | \n 07-04-2017 | \n Gujarat Lions | \n Kolkata Knight Riders | \n Kolkata Knight Riders | \n field | \n normal | \n 0 | \n Kolkata Knight Riders | \n 0 | \n 10 | \n CA Lynn | \n Saurashtra Cricket Association Stadium | \n Nitin Menon | \n CK Nandan | \n
\n \n | 4 | \n IPL-2017 | \n Indore | \n 08-04-2017 | \n Rising Pune Supergiant | \n Kings XI Punjab | \n Kings XI Punjab | \n field | \n normal | \n 0 | \n Kings XI Punjab | \n 0 | \n 6 | \n GJ Maxwell | \n Holkar Cricket Stadium | \n AK Chaudhary | \n C Shamshuddin | \n
\n \n | 5 | \n IPL-2017 | \n Bangalore | \n 08-04-2017 | \n Royal Challengers Bangalore | \n Delhi Daredevils | \n Royal Challengers Bangalore | \n bat | \n normal | \n 0 | \n Royal Challengers Bangalore | \n 15 | \n 0 | \n KM Jadhav | \n M Chinnaswamy Stadium | \n NaN | \n NaN | \n
\n \n
\n
"
+ },
+ "metadata": {},
+ "execution_count": 8
+ }
+ ],
"source": [
- "# Insert your solution here"
+ "new_df=df\n",
+ "new_df.columns = df.columns.str.replace(' ','_')\n",
+ "new_df.head"
]
},
{
@@ -182,8 +386,6 @@
]
},
{
- "cell_type": "markdown",
- "metadata": {},
"source": [
"# Step 3\n",
"\n",
@@ -204,11 +406,15 @@
"\n",
"https://towardsdatascience.com/one-simple-trick-for-speeding-up-your-python-code-with-numpy-1afc846db418\n",
"\n"
- ]
+ ],
+ "cell_type": "code",
+ "metadata": {},
+ "execution_count": null,
+ "outputs": []
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
@@ -219,7 +425,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
@@ -233,9 +439,17 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 15,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "96\nDuration: 11.977692365646362 seconds\n"
+ ]
+ }
+ ],
"source": [
"start = time.time()\n",
"verified_elements = []\n",
@@ -257,11 +471,20 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 29,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "96\nDuration: 0.028920412063598633 seconds\n"
+ ]
+ }
+ ],
"source": [
- "# Insert answer here\n",
+ "start=time.time()\n",
+ "verified_elements=np.intersect1d(subset_elements,all_elements)\n",
"\n",
"print(len(verified_elements))\n",
"print('Duration: {} seconds'.format(time.time() - start))"
@@ -276,11 +499,20 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 28,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "96\nDuration: 0.005990028381347656 seconds\n"
+ ]
+ }
+ ],
"source": [
- "# Insert answer here\n",
+ "start=time.time()\n",
+ "verified_elements=list(set(all_elements)&set(subset_elements))\n",
"\n",
"print(len(verified_elements))\n",
"print('Duration: {} seconds'.format(time.time() - start))"
@@ -330,9 +562,17 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "============================= test session starts =============================\nplatform win32 -- Python 3.9.1, pytest-6.2.1, py-1.10.0, pluggy-0.13.1\nrootdir: c:\\Users\\Anurag\\Documents\\GitHub\\Python-ifed-challenge-\ncollected 4 items\n\ntest_nearest_square.py .... [100%]\n\n============================== 4 passed in 0.02s ==============================\n"
+ ]
+ }
+ ],
"source": [
"! pytest test_nearest_square.py"
]
@@ -386,11 +626,28 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 71,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "Type 1: normal\nType 2: fairy\n"
+ ]
+ }
+ ],
"source": [
- "# Insert your code here"
+ "import requests\n",
+ "\n",
+ "url = \"http://pokeapi.co/api/v2/pokemon/jigglypuff/\"\n",
+ "\n",
+ "payload = \"\"\n",
+ "response = requests.request(\"GET\", url, data=payload)\n",
+ "\n",
+ "data = response.json()\n",
+ "print(\"Type 1:\",data[\"types\"][0][\"type\"][\"name\"])\n",
+ "print(\"Type 2:\",data[\"types\"][1][\"type\"][\"name\"])\n"
]
},
{
@@ -404,11 +661,43 @@
},
{
"cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [],
+ "execution_count": 72,
+ "metadata": {
+ "tags": []
+ },
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "fighting\npoison\nsteel\nfighting\nbug\ndark\n"
+ ]
+ }
+ ],
"source": [
- "# Insert your code here"
+ "url1=(data[\"types\"][0][\"type\"][\"url\"])\n",
+ "url2=(data[\"types\"][1][\"type\"][\"url\"])\n",
+ "\n",
+ "payload1 = \"\"\n",
+ "payload2 = \"\"\n",
+ "\n",
+ "response1 = requests.request(\"GET\", url1, data=payload1)\n",
+ "response2 = requests.request(\"GET\", url2, data=payload2)\n",
+ "\n",
+ "data1 = response1.json()\n",
+ "data2 = response2.json()\n",
+ "\n",
+ "for i in range(len(data1[\"damage_relations\"][\"double_damage_from\"])):\n",
+ " print(data1[\"damage_relations\"][\"double_damage_from\"][i][\"name\"])\n",
+ " \n",
+ "for i in range(len(data2[\"damage_relations\"][\"double_damage_from\"])):\n",
+ " print(data2[\"damage_relations\"][\"double_damage_from\"][i][\"name\"])\n",
+ "\n",
+ "for i in range(len(data1[\"damage_relations\"][\"half_damage_from\"])):\n",
+ " print(data1[\"damage_relations\"][\"half_damage_from\"][i][\"name\"])\n",
+ "\n",
+ "for i in range(len(data2[\"damage_relations\"][\"half_damage_from\"])):\n",
+ " print(data2[\"damage_relations\"][\"half_damage_from\"][i][\"name\"])\n"
]
},
{
@@ -420,11 +709,50 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": 74,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "mankey,primeape,poliwrath,machop,machoke,\n",
+ "\n",
+ "bulbasaur,ivysaur,venusaur,weedle,kakuna,\n",
+ "\n",
+ "magnemite,magneton,forretress,steelix,scizor,\n",
+ "\n"
+ ]
+ }
+ ],
"source": [
- "# Insert your code here"
+ "url1=(data[\"types\"][0][\"type\"][\"url\"])\n",
+ "url2=(data[\"types\"][1][\"type\"][\"url\"])\n",
+ "\n",
+ "payload=\"\"\n",
+ "payload1 = \"\"\n",
+ "payload2 = \"\"\n",
+ "\n",
+ "response = requests.request(\"GET\", url, data=payload)\n",
+ "response1 = requests.request(\"GET\", url1, data=payload1)\n",
+ "response2 = requests.request(\"GET\", url2, data=payload2)\n",
+ "\n",
+ "pdata = response.json()\n",
+ "data1 = response1.json()\n",
+ "data2 = response2.json()\n",
+ "\n",
+ "ddf=[]\n",
+ "for i in range(len(data1[\"damage_relations\"][\"double_damage_from\"])):\n",
+ " ddf.append(data1[\"damage_relations\"][\"double_damage_from\"][i][\"url\"])\n",
+ "\n",
+ "for i in range(len(data2[\"damage_relations\"][\"double_damage_from\"])):\n",
+ " ddf.append(data2[\"damage_relations\"][\"double_damage_from\"][i][\"url\"])\n",
+ "\n",
+ "for i in range(len(ddf)):\n",
+ " pdata = requests.request(\"GET\", ddf[i], data=payload).json()\n",
+ " for j in range(5):\n",
+ " print(pdata[\"pokemon\"][j][\"pokemon\"][\"name\"],end=',')\n",
+ " print(\"\\n\")"
]
},
{
@@ -438,21 +766,14 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 68,
"metadata": {},
"outputs": [
{
- "name": "stdout",
"output_type": "stream",
+ "name": "stdout",
"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",
- "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"
+ "============================= test session starts =============================\nplatform win32 -- Python 3.9.1, pytest-6.2.1, py-1.10.0, pluggy-0.13.1\nrootdir: c:\\Users\\Anurag\\Documents\\GitHub\\Python-ifed-challenge-\ncollected 4 items\n\ntest_abilities.py .... [100%]\n\n============================== 4 passed in 1.38s ==============================\n"
]
}
],
@@ -501,9 +822,13 @@
],
"metadata": {
"kernelspec": {
- "display_name": "Python 3",
- "language": "python",
- "name": "python3"
+ "name": "python3",
+ "display_name": "Python 3.9.1 64-bit",
+ "metadata": {
+ "interpreter": {
+ "hash": "bb11029e2afac0e7f6618262482e01595b9fa9c6642c63436503e9a1c447fc40"
+ }
+ }
},
"language_info": {
"codemirror_mode": {
@@ -515,7 +840,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.6.9"
+ "version": "3.9.1-final"
}
},
"nbformat": 4,
diff --git a/__pycache__/ability.cpython-39.pyc b/__pycache__/ability.cpython-39.pyc
new file mode 100644
index 0000000..37b97ce
Binary files /dev/null and b/__pycache__/ability.cpython-39.pyc differ
diff --git a/__pycache__/nearest_square.cpython-39.pyc b/__pycache__/nearest_square.cpython-39.pyc
new file mode 100644
index 0000000..c9afa9c
Binary files /dev/null and b/__pycache__/nearest_square.cpython-39.pyc differ
diff --git a/__pycache__/test_abilities.cpython-39-pytest-6.2.1.pyc b/__pycache__/test_abilities.cpython-39-pytest-6.2.1.pyc
new file mode 100644
index 0000000..2d181a9
Binary files /dev/null and b/__pycache__/test_abilities.cpython-39-pytest-6.2.1.pyc differ
diff --git a/__pycache__/test_nearest_square.cpython-39-pytest-6.2.1.pyc b/__pycache__/test_nearest_square.cpython-39-pytest-6.2.1.pyc
new file mode 100644
index 0000000..76e5082
Binary files /dev/null and b/__pycache__/test_nearest_square.cpython-39-pytest-6.2.1.pyc differ
diff --git a/ability.py b/ability.py
new file mode 100644
index 0000000..d469b47
--- /dev/null
+++ b/ability.py
@@ -0,0 +1,10 @@
+import requests
+def ability(name):
+ url = "http://pokeapi.co/api/v2/pokemon/"+name+"/"
+ payload=""
+ response = requests.request("GET", url, data=payload)
+ data = response.json()
+ ality=[]
+ for i in data["abilities"]:
+ ality.append(i['ability']['name'])
+ return ality
\ No newline at end of file
diff --git a/nearest_square.py b/nearest_square.py
new file mode 100644
index 0000000..8bfad15
--- /dev/null
+++ b/nearest_square.py
@@ -0,0 +1,7 @@
+import math
+
+def nearest_square(n):
+ if n<1:
+ return 0
+ else:
+ return(math.floor(n**0.5)**2)
\ No newline at end of file
diff --git a/pokedex.py b/pokedex.py
new file mode 100644
index 0000000..b0540d2
--- /dev/null
+++ b/pokedex.py
@@ -0,0 +1,90 @@
+import PySimpleGUI as sg
+import requests
+
+
+layout = [[sg.Text("Enter the name of Pokemon:")],
+ [sg.Input(key='-INPUT-')],
+ [sg.Text(size=(100,1), key='-OUTPUT1-')],
+ [sg.Text(size=(100,1), key='-OUTPUT2-')],
+ [sg.Text(size=(100,3), key='-OUTPUT3-')],
+ [sg.Text(size=(100,15), key='-OUTPUT4-')],
+ [sg.Text(size=(100,1), key='-OUTPUT5-')],
+ [sg.Button('Search'), sg.Button('Quit')]]
+
+import requests
+def ability(name):
+ url = "http://pokeapi.co/api/v2/pokemon/"+name+"/"
+ payload=""
+ response = requests.request("GET", url, data=payload)
+ data = response.json()
+ ality=[]
+ for i in data["abilities"]:
+ ality.append(i['ability']['name'])
+ return ality
+
+
+
+window = sg.Window('PokeDex', layout)
+
+while True:
+ event, values = window.read()
+ if event == sg.WINDOW_CLOSED or event == 'Quit':
+ break
+
+ Details="Name of the pokemon:"+values['-INPUT-']
+ window['-OUTPUT1-'].update(Details)
+ name=values["-INPUT-"]
+
+ #TYPE OF POKEMON
+
+ urll = "http://pokeapi.co/api/v2/pokemon/"+name+"/"
+ urls=[]
+ tp=[]
+ data = requests.get(urll).json()
+ for i in range (2):
+ poke_type=data["types"][i]['type']['name']
+ urls.append(data["types"][i]['type']['url'])
+ tp.append(poke_type)
+
+ Details="Type of pokemon is: "+str(tp)
+ window['-OUTPUT2-'].update(Details)
+
+ #DOUBLE DAMAGE FROM
+
+ Details="Double Damage from: \n"
+ d_dmg_url=[]
+ cn=0
+ tpp=tp
+ tp=[]
+ for url in urls:
+ poke_type=requests.get(url).json()
+ Details+="Double Damage for "+tpp[cn]+" by: "
+ cn+=1
+ for j in poke_type["damage_relations"]["double_damage_from"]:
+ Details+=j["name"]+' '
+ tp.append(j["name"])
+ d_dmg_url.append(j["url"])
+ Details+='\n'
+ window['-OUTPUT3-'].update(Details)
+
+ #LISTING 5 POKEMON
+
+ Details='The 5 pokemons which gives the given pokemon double damage:\n'
+ print(d_dmg_url)
+ for i in range(len(d_dmg_url)):
+ dat=requests.get(d_dmg_url[i]).json()
+ Details+=("Pokemon of Type: "+tp[i]+'\n')
+ for j in range(5):
+ Details+=(dat["pokemon"][j]["pokemon"]["name"])
+ if j!=4:
+ Details+=(',')
+ Details+=("\n\n")
+
+ window['-OUTPUT4-'].update(Details)
+
+ #ABILITY
+
+ Details="Ability: "+str(ability(values['-INPUT-']))
+ window['-OUTPUT5-'].update(Details)
+
+window.close()
\ No newline at end of file
diff --git a/step_4.py b/step_4.py
new file mode 100644
index 0000000..5a074d2
--- /dev/null
+++ b/step_4.py
@@ -0,0 +1,60 @@
+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 function1():
+ """
+Function 1:
+The default method for finding intersection of two sets.
+ """
+
+ start = time.time()
+ verified_elements = []
+
+ for element in subset_elements:
+ if element in all_elements:
+ verified_elements.append(element)
+
+ print(len(verified_elements))
+ print('Duration: {} seconds'.format(time.time() - start))
+
+def function2():
+ """
+Function 2:
+The method of finding intersection of two sets using built-in function of numpy.
+ """
+
+ start=time.time()
+ verified_elements=np.intersect1d(all_elements,subset_elements)
+
+ print(len(verified_elements))
+ print('Duration: {} seconds'.format(time.time() - start))
+
+def function3():
+ """
+Function 3:
+The method of finding intersection of two sets using data structure.
+ """
+
+ start=time.time()
+ verified_elements=list(set(all_elements)&set(subset_elements))
+
+ print(len(verified_elements))
+ print('Duration: {} seconds'.format(time.time() - start))
+
+def main():
+ print(function1.__doc__)
+ function1()
+ print(function2.__doc__)
+ function2()
+ print(function3.__doc__)
+ function3()
+
+if __name__ == "__main__":
+ main()
\ No newline at end of file