diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb
index ee9444d..67eef5d 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",
+ "It's the software running on production servers to handle live users and data of the intended audience.\n",
+ "\n",
"#### Clean \n",
- "(Insert answer here)\n",
+ "Clean means that the code should be simple, readable and consise, so that it's easy to read, write and maintain.\n",
"#### Modular\n",
- "(Insert answer here)\n",
+ "Modular means a design approach that subdivides a system into smaller parts that can be independently created and then used in different systems, example functions. It makes our code more organized, efficient, and reusable.\n",
"#### Module\n",
- "(Insert answer here)\n",
+ "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)"
+ "Refactoring is a way to restructure your code to improve its internal structure without changing its external function at all. "
]
},
{
@@ -93,9 +94,59 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 2,
"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": 2
+ }
+ ],
"source": [
"import pandas as pd\n",
"df = pd.read_csv('matches.csv', sep=',')\n",
@@ -113,9 +164,59 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"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": 3
+ }
+ ],
"source": [
"new_df = df.rename(columns={'team 1': 'team_1',\n",
" 'team 2': 'team_2',\n",
@@ -139,9 +240,59 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 4,
"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": 4
+ }
+ ],
"source": [
"labels = list(df.columns)\n",
"labels[0] = labels[0].replace(' ', '_')\n",
@@ -167,11 +318,63 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 5,
"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": 5
+ }
+ ],
"source": [
- "# Insert your solution here"
+ "for i in range(len(df.columns)):\n",
+ " df.rename(columns={df.columns[i]: df.columns[i].replace(' ','_')}, inplace=True)\n",
+ "df.head()"
]
},
{
@@ -208,7 +411,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
@@ -219,7 +422,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
@@ -233,9 +436,17 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 8,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "96\nDuration: 8.520490884780884 seconds\n"
+ ]
+ }
+ ],
"source": [
"start = time.time()\n",
"verified_elements = []\n",
@@ -257,11 +468,24 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 10,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "96\nDuration: 0.026564359664916992 seconds\n"
+ ]
+ }
+ ],
"source": [
- "# Insert answer here\n",
+ "start = time.time()\n",
+ "subsetArr=np.array(subset_elements)\n",
+ "allArr=np.array(all_elements)\n",
+ "verified_elements = np.array([])\n",
+ "\n",
+ "verified_elements=np.intersect1d(subsetArr,allArr)\n",
"\n",
"print(len(verified_elements))\n",
"print('Duration: {} seconds'.format(time.time() - start))"
@@ -276,14 +500,23 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 20,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "96\nDuration: 0.006795406341552734 seconds\n"
+ ]
+ }
+ ],
"source": [
- "# Insert answer here\n",
+ "start = time.time()\n",
+ "verified_elements = list(set(subset_elements)&set(all_elements))\n",
"\n",
"print(len(verified_elements))\n",
- "print('Duration: {} seconds'.format(time.time() - start))"
+ "print(f'Duration: {time.time() - start} seconds')"
]
},
{
@@ -330,9 +563,17 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "\u001b[1m============================= test session starts ==============================\u001b[0m\nplatform linux -- Python 3.8.5, pytest-6.2.1, py-1.10.0, pluggy-0.13.1\nrootdir: /home/somubuntu/Desktop/Python-ifed-challenge-pvt\nplugins: xonsh-0.9.13\ncollected 4 items \u001b[0m\n\ntest_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 +627,27 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 10,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "Discord channel name: Pikachu\nPokekon Type: ELECTRIC\n"
+ ]
+ }
+ ],
"source": [
- "# Insert your code here"
+ "import requests,json\n",
+ "\n",
+ "response=requests.get(\"https://pokeapi.co/api/v2/pokemon/pikachu\")\n",
+ "response.raise_for_status()\n",
+ "pikachuData=response.json()\n",
+ "typeData=pikachuData['types'][0]\n",
+ "typeName=typeData['type']['name']\n",
+ "print(\"Discord channel name: Pikachu\")\n",
+ "print(\"Pokekon Type: \",typeName.upper())"
]
},
{
@@ -404,11 +661,25 @@
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": 11,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "Takes damage from: GROUND & FLYING types.\n"
+ ]
+ }
+ ],
"source": [
- "# Insert your code here"
+ "typeURL=typeData['type']['url']\n",
+ "response=requests.get(typeURL)\n",
+ "pikachuData=response.json()\n",
+ "damageData=pikachuData['damage_relations']\n",
+ "double_damage_from=damageData['double_damage_from'][0]['name']\n",
+ "half_damage_from=damageData['half_damage_from'][0]['name']\n",
+ "print(f'Takes damage from: {double_damage_from.upper()} & {half_damage_from.upper()} types.')"
]
},
{
@@ -420,11 +691,24 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": 12,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "sandshrew\nsandslash\nnidoqueen\nnidoking\ndiglett\n"
+ ]
+ }
+ ],
"source": [
- "# Insert your code here"
+ "response=requests.get(\"https://pokeapi.co/api/v2/type/\"+double_damage_from)\n",
+ "response.raise_for_status()\n",
+ "typeData=response.json()\n",
+ "pikachuData=typeData['pokemon']\n",
+ "for i in range(5):\n",
+ " print(pikachuData[i]['pokemon']['name'])"
]
},
{
@@ -515,7 +799,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.6.9"
+ "version": "3.8.5-final"
}
},
"nbformat": 4,
diff --git a/__pycache__/ability.cpython-38.pyc b/__pycache__/ability.cpython-38.pyc
new file mode 100644
index 0000000..2427a61
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..d07011d
Binary files /dev/null and b/__pycache__/nearest_square.cpython-38.pyc differ
diff --git a/__pycache__/pokedexFunc.cpython-38.pyc b/__pycache__/pokedexFunc.cpython-38.pyc
new file mode 100644
index 0000000..08e71c3
Binary files /dev/null and b/__pycache__/pokedexFunc.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..8a44c6f
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..2e231ec
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..ad5215a
--- /dev/null
+++ b/ability.py
@@ -0,0 +1,11 @@
+import requests,json
+
+def ability(pokeName):
+ response=requests.get("https://pokeapi.co/api/v2/pokemon/"+pokeName)
+ response.raise_for_status()
+ pikachuData=response.json()
+ abilitiesData=pikachuData['abilities']
+ abilities=[]
+ for ability in abilitiesData:
+ abilities.append(ability['ability']['name'])
+ return abilities
diff --git a/nearest_square.py b/nearest_square.py
new file mode 100644
index 0000000..0f8ba6f
--- /dev/null
+++ b/nearest_square.py
@@ -0,0 +1,7 @@
+def nearest_square(n):
+ if n>0:
+ for i in range(n):
+ if i*i <= n:
+ nearSq = i*i
+ return nearSq
+ return 0
diff --git a/pokedex.py b/pokedex.py
new file mode 100644
index 0000000..9dbbb73
--- /dev/null
+++ b/pokedex.py
@@ -0,0 +1,34 @@
+import PySimpleGUI as sg
+from pokedexFunc import pokeType,ability,TypeDoubleDmg,DoubleDmg5
+
+sg.theme('DarkBlue')
+layout = [[sg.Text("Enter Pokemon Name: ")],
+ [sg.Input(size=(35,1),key='-INPUT-')],
+ [sg.Text(size=(35,3), key='-Type-')],
+ [sg.Text(size=(35,2), key='-DDF-')],
+ [sg.Text(size=(35,7), key='-DDP-')],
+ [sg.Text(size=(35,8), key='-ABILITIES-')],
+ [sg.Button('Get Details'), sg.Button('Quit')]]
+
+window = sg.Window('POKEDEX', layout, alpha_channel=0.95)
+
+while True:
+ event, values = window.read()
+
+ if event == sg.WINDOW_CLOSED or event == 'Quit':
+ break
+
+ typeName=pokeType(values['-INPUT-'].lower())
+ double_damage_from=TypeDoubleDmg(typeName)
+ DoubleDamagePoksList=DoubleDmg5(double_damage_from)
+ doubleDamagePoks='\n--> '.join([str(i).upper() for i in DoubleDamagePoksList])
+ abilitiesList=ability(values['-INPUT-'].lower())
+ abilities='\n--> '.join([str(i).upper() for i in abilitiesList])
+
+ window['-Type-'].update('\nType: '+typeName.upper())
+ window['-DDF-'].update('Double Damage from type: '+double_damage_from.upper())
+ window['-DDP-'].update(f'Double Damage from pokemons:\n--> {doubleDamagePoks}')
+ window['-ABILITIES-'].update(f'Abilities:\n--> {abilities}')
+
+
+window.close()
\ No newline at end of file
diff --git a/pokedexFunc.py b/pokedexFunc.py
new file mode 100644
index 0000000..eeb0128
--- /dev/null
+++ b/pokedexFunc.py
@@ -0,0 +1,91 @@
+#! python3
+# pokedexFunc.py
+
+import requests,json
+
+def pokeType(pokeName):
+ '''Returns the type of pokemon passed in arguments
+
+ PARAMETERS:
+ -----------
+ pokeName : string
+ Name of the pokemon
+
+ RETURNS:
+ ----------
+ typeName : string
+ Type of the pokemon
+ '''
+
+ response=requests.get("https://pokeapi.co/api/v2/pokemon/"+pokeName)
+ response.raise_for_status()
+ pikachuData=response.json()
+ typeData=pikachuData['types'][0]
+ typeName=typeData['type']['name']
+ return typeName
+
+def TypeDoubleDmg(typeName):
+ '''Returns the pokemon type which gives 2x damage to the type passed in arguments
+
+ PARAMETERS:
+ -----------
+ typeName : string
+ Type of pokemon
+
+ RETURNS:
+ -----------
+ double_damage_from: string
+ Type of pokemon which gives 2x damage to pokeName
+ '''
+
+ response=requests.get("https://pokeapi.co/api/v2/type/"+typeName)
+ pikachuData=response.json()
+ damageData=pikachuData['damage_relations']
+ double_damage_from=damageData['double_damage_from'][0]['name']
+ return double_damage_from
+
+def DoubleDmg5(double_damage_from):
+ '''Returns the list of five pokemons of the type passed in arguments
+
+ PARAMETERS:
+ -----------
+ double_damage_from : string
+ Type of pokemon
+
+ RETURNS:
+ ------------
+ DDF : list
+ Names of five pokemon of type double_damage_from, in a list
+ '''
+
+ response=requests.get("https://pokeapi.co/api/v2/type/"+double_damage_from)
+ response.raise_for_status()
+ typeData=response.json()
+ pikachuData=typeData['pokemon']
+ DDF=[]
+ for i in range(5):
+ DDF.append(pikachuData[i]['pokemon']['name'])
+ return DDF
+
+def ability(pokeName):
+ '''Returns the list of abilities of the pokemon passed in arguments
+
+ PARAMETERS:
+ -----------
+ pokeName : string
+ Name of pokemon
+
+ RETURNS:
+ ------------
+ abilities : list
+ All abilities of pokeName, in a list
+ '''
+
+ response=requests.get("https://pokeapi.co/api/v2/pokemon/"+pokeName)
+ response.raise_for_status()
+ pikachuData=response.json()
+ abilitiesData=pikachuData['abilities']
+ abilities=[]
+ for ability in abilitiesData:
+ abilities.append(ability['ability']['name'])
+ return abilities
\ No newline at end of file
diff --git a/step_4.py b/step_4.py
new file mode 100644
index 0000000..fb4590a
--- /dev/null
+++ b/step_4.py
@@ -0,0 +1,126 @@
+#! python3
+# step_4.py
+""" STEP-4
+This script was made for learning how to optimize our python code.
+
+It reads data from two .txt files, and prints the
+number of lines which are same in both the .txt files.
+
+This script requires that `pandas` be installed within the Python
+environment you are running this script in.
+"""
+
+import time
+import pandas as pd
+import numpy as np
+
+def openFiles():
+ """Open two text files and stores each line in the of that file in a list
+ Parameters:
+ --------------
+ None
+
+ Returns:
+ -------------
+ subset_elements : list
+ a list of strings from subset_elemets.txt
+ all_elements : list
+ a list of strings from subset_elements.txt
+ """
+
+ 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')
+ return subset_elements,all_elements
+
+def appendOldWay(subset_elements,all_elements):
+ """Prints a list of elements and time taken to execute this function.
+
+ This function uses nested for loops and append() method to find the elements
+ which are present in both the lists passed as arguments, and stores them in a
+ new list. It prints the length of the new list along with time taken by this
+ function.
+
+ Parameters:
+ --------------
+ subset_elements : list
+ a list of strings
+ all_elements : list
+ a list of strings
+ Returns:
+ -------------
+ None
+ """
+ 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 appendNumPy(subset_elements, all_elements):
+ """Prints a list of elements and time taken to execute this function.
+
+ This function uses NumPy methods to find the elements which are present
+ in both the lists passed as arguments, and stores them in a new list.
+ It prints the length of the new list along with time taken by this
+ function.
+
+ Parameters:
+ --------------
+ subset_elements : list
+ a list of strings
+ all_elements : list
+ a list of strings
+ Returns:
+ -------------
+ None
+ """
+
+ start = time.time()
+ subsetArr=np.array(subset_elements)
+ allArr=np.array(all_elements)
+ verified_elements = np.array([])
+ verified_elements=np.intersect1d(subsetArr,allArr)
+ print(len(verified_elements))
+ print('Duration: {} seconds'.format(time.time() - start))
+
+def appendDataStruct(subset_elements,all_elements):
+ """Prints a list of elements and time taken to execute this function.
+
+ This function use of python data structures and set() method to find
+ the elements which are present in both the lists passed as arguments,
+ and stores them in a new list. It prints the length of the new list along
+ with time taken by this
+ function.
+
+ Parameters:
+ --------------
+ subset_elements : list
+ a list of strings
+ all_elements : list
+ a list of strings
+ Returns:
+ -------------
+ None
+ """
+
+ start = time.time()
+ verified_elements = list(set(subset_elements)&set(all_elements))
+ print(len(verified_elements))
+ print(f'Duration: {time.time() - start} seconds')
+
+def main():
+ subset_elements, all_elements=openFiles()
+ print('When Using old code with for loop--->')
+ appendOldWay(subset_elements,all_elements)
+ print("when using NumPy module's methods--->")
+ appendNumPy(subset_elements,all_elements)
+ print("When using python data structure's methods(sets)--->")
+ appendDataStruct(subset_elements,all_elements)
+
+if __name__=="__main__":
+ main()
\ No newline at end of file