diff --git a/Python-ifed.ipynb b/Python-ifed.ipynb
index ee9444d..a7800fb 100644
--- a/Python-ifed.ipynb
+++ b/Python-ifed.ipynb
@@ -62,15 +62,15 @@
"### Describe what each of the following means\n",
"\n",
"#### Production\n",
- "(Insert answer here)\n",
+ "Any code that is ready to be used by its userbase after testing.\n",
"#### Clean \n",
- "(Insert answer here)\n",
+ "A code which is easy to understand, modify and test.\n",
"#### Modular\n",
- "(Insert answer here)\n",
+ "Modular means to divide the code into different modules. It makes the program reusable and easy to maintain.\n",
"#### Module\n",
- "(Insert answer here)\n",
+ "Module is a file which has definitions which can be used in a script or in an interactive instance of the interpretor\n",
"#### Refactoring code\n",
- "(Insert answer here)"
+ "It is the process of restructuring the code without changing or adding anything to its functionality. It makes the code more readable."
]
},
{
@@ -93,9 +93,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",
@@ -167,11 +217,62 @@
},
{
"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": [
- "# Insert your solution here"
+ "df.columns = df.columns.str.replace(' ','_') # Replacing space with underscore\n",
+ "df.head()"
]
},
{
@@ -208,7 +309,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
@@ -219,7 +320,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
@@ -232,10 +333,6 @@
]
},
{
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
"source": [
"start = time.time()\n",
"verified_elements = []\n",
@@ -246,7 +343,11 @@
"\n",
"print(len(verified_elements))\n",
"print('Duration: {} seconds'.format(time.time() - start))"
- ]
+ ],
+ "cell_type": "code",
+ "metadata": {},
+ "execution_count": null,
+ "outputs": []
},
{
"cell_type": "markdown",
@@ -256,15 +357,28 @@
]
},
{
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
"source": [
- "# Insert answer here\n",
+ "#Starting the program\n",
+ "start = time.time()\n",
+ "\n",
+ "#finding intersection using intersect!d()\n",
+ "verified_elements= np.intersect1d(subset_elements, all_elements)\n",
"\n",
+ "#printing the number of common elements\n",
"print(len(verified_elements))\n",
"print('Duration: {} seconds'.format(time.time() - start))"
+ ],
+ "cell_type": "code",
+ "metadata": {},
+ "execution_count": 9,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "96\nDuration: 0.038300514221191406 seconds\n"
+ ]
+ }
]
},
{
@@ -276,12 +390,28 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 10,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "96\nDuration: 0.011659860610961914 seconds\n"
+ ]
+ }
+ ],
"source": [
- "# Insert answer here\n",
+ "start = time.time() #Starting the program\n",
+ "\n",
+ "#converting list to set\n",
+ "a =set(subset_elements)\n",
+ "b =set(all_elements)\n",
"\n",
+ "#finding common elements in set\n",
+ "verified_elements = a.intersection(b)\n",
+ "\n",
+ "#printing the number of common elements\n",
"print(len(verified_elements))\n",
"print('Duration: {} seconds'.format(time.time() - start))"
]
@@ -330,9 +460,17 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 12,
"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/siddharth/Desktop/Python-ifed-challenge\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 +524,29 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 2,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "ghost\npoison\n"
+ ]
+ }
+ ],
"source": [
- "# Insert your code here"
+ "import requests\n",
+ "import json\n",
+ "\n",
+ "#Get json object \n",
+ "url = \"https://pokeapi.co/api/v2/pokemon/gengar\"\n",
+ "res = requests.get(url)\n",
+ "obj = res.json()\n",
+ "\n",
+ "#Get information of the pokemon and then get its type name.\n",
+ "for info in obj['types']:\n",
+ " print(info['type']['name'])"
]
},
{
@@ -404,11 +560,43 @@
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": 15,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "poison\nfairy\nground\ngrass\ndark\nbug\npsychic\nfighting\nghost\n"
+ ]
+ }
+ ],
"source": [
- "# Insert your code here"
+ "import requests\n",
+ "import json\n",
+ "\n",
+ "dam_from = set() #Stores type of pokemons this type take damage from\n",
+ "\n",
+ "#Get json object of gengar\n",
+ "url = \"https://pokeapi.co/api/v2/pokemon/gengar\"\n",
+ "res = requests.get(url)\n",
+ "obj = res.json()\n",
+ "\n",
+ "#run a loop to get URL of pokemon's type detail.\n",
+ "for info in obj['types']:\n",
+ " link = info['type']['url']\n",
+ " r = requests.get(link)\n",
+ " detail = r.json()\n",
+ "\n",
+ " #Searching for all damage gengar can take from\n",
+ " for half in detail['damage_relations']['half_damage_from']:\n",
+ " dam_from.add(half['name'])\n",
+ " for double in detail['damage_relations']['double_damage_from']:\n",
+ " dam_from.add(double['name'])\n",
+ "\n",
+ "#printing the result\n",
+ "for pokemon in dam_from:\n",
+ " print(pokemon)"
]
},
{
@@ -422,9 +610,65 @@
"cell_type": "code",
"execution_count": 3,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "ghost\n",
+ "-------\n",
+ "umbreon\n",
+ "murkrow\n",
+ "sneasel\n",
+ "houndour\n",
+ "houndoom\n",
+ "\n",
+ "\n",
+ "psychic\n",
+ "-------\n",
+ "abra\n",
+ "kadabra\n",
+ "alakazam\n",
+ "slowpoke\n",
+ "slowbro\n",
+ "\n",
+ "\n"
+ ]
+ }
+ ],
"source": [
- "# Insert your code here"
+ "import requests\n",
+ "import json\n",
+ "\n",
+ "dam_from = set()# Stores names of pokemon which have double damage from the type.\n",
+ "\n",
+ "#getting json from webpage\n",
+ "url = \"https://pokeapi.co/api/v2/pokemon/gengar\"\n",
+ "res = requests.get(url)\n",
+ "obj = res.json()\n",
+ "c=0\n",
+ "#running elements of obj\n",
+ "for w in obj['types']:\n",
+ "\n",
+ " link = w['type']['url'] \n",
+ " r = requests.get(link)\n",
+ " a = r.json()# get json of type detail\n",
+ "\n",
+ " #print pokemon type which has double damage from\n",
+ " print(a['damage_relations']['double_damage_from'][c]['name'])\n",
+ " print('-------')\n",
+ " c+=1\n",
+ "\n",
+ " #Get tink to get list of pokemon in the above type\n",
+ " link1 = a['damage_relations']['double_damage_from'][1]['url']\n",
+ " res1 = requests.get(link1)\n",
+ " b = res1.json()\n",
+ " \n",
+ " #printing the pokemon names of the above printed type\n",
+ " for i in range(5):\n",
+ " print(b['pokemon'][i]['pokemon']['name'])\n",
+ " print('\\n')\n",
+ "\n"
]
},
{
@@ -438,21 +682,21 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 16,
"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",
+ "platform linux -- Python 3.8.5, pytest-6.2.1, py-1.10.0, pluggy-0.13.1\n",
+ "rootdir: /home/siddharth/Desktop/Python-ifed-challenge\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 1.84s\u001b[0m\u001b[32m ===============================\u001b[0m\n"
]
}
],
@@ -515,7 +759,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.6.9"
+ "version": "3.8.2-final"
}
},
"nbformat": 4,
diff --git a/ability.py b/ability.py
new file mode 100644
index 0000000..797311d
--- /dev/null
+++ b/ability.py
@@ -0,0 +1,18 @@
+import json,requests
+
+def ability(pokemon):
+
+ abilities = [] #To store abilities
+
+ url = 'https://pokeapi.co/api/v2/pokemon/'+pokemon
+ res = requests.get(url)
+ detail = res.json() # to get details in list
+
+ #appending abilities to the list
+ for i in detail['abilities']:
+ abilities.append(i['ability']['name'])
+
+ return abilities
+ability.__doc__ = """
+ This function returns Abilities of a pokemon. """
+
diff --git a/nearest_square.py b/nearest_square.py
new file mode 100644
index 0000000..5c58d0f
--- /dev/null
+++ b/nearest_square.py
@@ -0,0 +1,14 @@
+import math
+def nearest_square(n):
+
+ #If n is positive the square of integral part of square root will give the answer
+ if n>0:
+ i=int(math.sqrt(n))
+ return (i*i)
+
+ # If n negative then the closest solution will be zero
+ else:
+ return 0
+
+nearest_square.__doc__ = """
+ This function finds the nearest perfect square number which is less than or equal to the number. """
diff --git a/step_4.py b/step_4.py
new file mode 100644
index 0000000..deb5ce7
--- /dev/null
+++ b/step_4.py
@@ -0,0 +1,42 @@
+import time
+import pandas as pd
+import numpy as np
+
+def by_Numpy(subset_elements,all_elements):
+
+ #starting of function
+ start = time.time()
+
+ #Getting all the common elements using intersection1d
+ verified_elements= np.intersect1d(subset_elements, all_elements)
+
+
+ # print number of elements common and time taken
+ print(len(verified_elements))
+ print('Duration: {} seconds'.format(time.time() - start))
+
+
+by_Numpy.__doc__ = """
+This function finds number of common value from two lists using numpy
+ """
+
+
+def bySets(subset_elements,all_elements):
+ #start of the function
+ start = time.time()
+
+ #convert lists to sets
+ a =set(subset_elements)
+ b =set(all_elements)
+
+ #find the elements in intersection of sets
+ verified_elements = a.intersection(b)
+
+ # print number of elements common and time taken
+ print(len(verified_elements))
+ print('Duration: {} seconds'.format(time.time() - start))
+
+
+bySets.__doc__ = """
+This function finds number of common value from two lists by converting them to sets and finding number of intersection.
+ """