Skip to content

Commit be06ce1

Browse files
committed
reorganized the repository
1 parent 226a011 commit be06ce1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+431
-29
lines changed

README.md

+11-3

algorithm/recursion/fibonacci.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,9 @@ def fibo(n):
55
return 1
66
return fibo(n-1) + fibo(n-2)
77

8-
print(fibo(7))
8+
def iter(n):
9+
a,b = 0,1
10+
for x in range(n):
11+
a,b = b,a+b
12+
return a
13+
print(iter(1))

challenge/func_with_list.py

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
## Challenge exercise - list, tuple, dictionary and functions.
2+
# Sample execution code is provided at the bottom, you may run it now
3+
# to see and get a feel for the existing output then build each function
4+
# and re-run the script.
5+
from collections import Counter
6+
7+
buckets = [ ('john.doe@example.com',{'first_name':'john','last_name':'doe'}),
8+
('jane.doe@example.com',{'first_name':'jane','last_name':'doe'}),
9+
('derek.zoo@example.com',{'first_name':'derek','last_name':'zoolander'}),
10+
('murph.cooper@example.com',{'first_name':'murph','last_name':'cooper'}),
11+
('ned.stark@example.com',{'first_name':'ned','last_name':'stark'})
12+
]
13+
14+
# Question 1: Create a function that returns all last names in the list
15+
# with the number of occurances of that last name, example 'doe': 2, 'stark': 1
16+
# use the Counter function from collections module to count the occurances with ease.
17+
def get_last_name_count(list_of_records):
18+
"""
19+
fill in docstring
20+
"""
21+
m = { }
22+
23+
for rec in list_of_records:
24+
ln = rec[1].get("last_name")
25+
if m.get(ln) is None:
26+
m[ln] = 1
27+
else :
28+
m[ln] = m.get(ln) + 1
29+
30+
print("count map", m)
31+
## Write code below ##
32+
pass
33+
## end of function ##
34+
35+
36+
# Question 2: Create a function that compares first and last names of records
37+
# given the email address, first and last names to compare. Exact matches only,
38+
# ignore case. Return True if exact match, return False otherwise.
39+
def compare_full_name(list_of_records, email, first_name, last_name):
40+
"""
41+
fill in docstring
42+
"""
43+
for rec in list_of_records:
44+
if rec[1].get("first_name") == first_name and rec[1].get("last_name") == last_name:
45+
return True
46+
47+
return False
48+
## Write code below ##
49+
50+
## end of function ##
51+
52+
# (CHALLENGE) Question 3: Create a function that can reset the value for first_name
53+
# and last_name for a record found with a specific email address
54+
# while leaving the rest of the list unchanged, if the email address
55+
# does not exist, then append a new record to the list with the new email
56+
# address, first name and last name.
57+
# Hint: Solutions use the enumerate function to track index of a record.
58+
def update_record(list_of_records, email, first_name, last_name):
59+
"""
60+
fill in docstring
61+
"""
62+
## Write code below ##
63+
pass
64+
## end of function ##
65+
66+
def divider():
67+
print()
68+
print("-"*40)
69+
print()
70+
71+
print("The last names and their counts are as follows:")
72+
result = get_last_name_count(buckets)
73+
# un-comment the code below once your get_last_name_count function works
74+
# for k, v in result.items():
75+
# print(f"{k}: {v}")
76+
divider()
77+
78+
print("Does ned's first and last name match our records?")
79+
print(compare_full_name(buckets,'ned.stark@example.com','ned','stark'))
80+
print(compare_full_name(buckets,'john.doe@example.com','john','doe'))
81+
divider()
82+
83+
print("Changing john's first name to jon and last name to snow")
84+
update_record(buckets,'john.doe@example.com','jon','snow')
85+
divider()
86+
87+
print("Adding new record ironman@example.com")
88+
update_record(buckets,'ironman@example.com','iron','man')
89+
divider()
90+
91+
print("Updated last names and their count are as follows:")
92+
result = get_last_name_count(buckets)
93+
# un-comment the code below once your get_last_name_count function works
94+
# for k, v in result.items():
95+
# print(f"{k}: {v}")
96+
divider()
97+
98+
print("Full list")
99+
for item in buckets:
100+
record_email, full_name = item
101+
print(f"Email: {record_email}, first name: {full_name['first_name']}, last_name: {full_name['last_name']}")

concepts/calling_script/caller.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
import os
2+
from main_file import call_method
3+
import main_file as abc
24
os.system("python3 main_file.py -d arg1 -p arg2 -e arg3")

concepts/calling_script/main_file.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from optparse import OptionParser
22

3+
def call_method(arg = None):
4+
print("method called with arg", arg)
5+
36
if __name__ == '__main__':
47
# provide options
58
parser = OptionParser()
File renamed without changes.

concepts/function/function_args.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
def cheeseshop( *argum, **keywords1):
2+
print("-- Do you have any", "?")
3+
for arg in argum:
4+
print(arg)
5+
print("-" * 40)
6+
for kw in keywords1:
7+
print(kw, ":", keywords1[kw])
8+
9+
cheeseshop("Heart", "dick", "pussy",
10+
vegina="Michael Palin",
11+
client="John Cleese",
12+
sketch="Cheese Shop Sketch")
13+
14+
#############################################
15+
16+
def parrot(voltage, state:'a stiff', action:'voom') -> bool:
17+
print("-- This parrot wouldn't", action, end=' ')
18+
print("if you put", voltage, "volts through it.", end=' ')
19+
print("E's", state, "!")
20+
return "return"
21+
22+
# unpacked the dictionary
23+
dict = {"state": "a stiff", "action":"voom"}
24+
parrot("a", **dict)
25+
26+
# unpacked the list and passed
27+
lst = ["a","b","c"]
28+
print(parrot(*lst) + parrot(*lst))

concepts/function/generator_function.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
# 2 second time and 3 third time
1313
def simpleGeneratorFun():
1414
yield 1
15+
print("returned 1st yield")
1516
yield 2
17+
print("returned 2nd yield")
1618
yield "3"
19+
print("returned 3rd yield")
1720

1821
o = simpleGeneratorFun()
1922
print(type(o))
@@ -24,7 +27,7 @@ def simpleGeneratorFun():
2427
print(next(o)); # In Python 3, __next__()
2528
print(next(o));
2629
print(next(o));
27-
print(next(o));
30+
# print(next(o));
2831

2932
######################################
3033

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# In Python, you can pass in functions as arguments to other functions.
2+
# I have a function below that takes a function and a list as an argument and runs the function using the list as a parameter.
3+
def run_func(func_name, some_list):
4+
return func_name(some_list)
5+
6+
7+
l1 = [6, 5, 4, 9, 10, 23, 12]
8+
print(run_func(sorted, l1))
9+
10+
if "a" == "b":
11+
pass
File renamed without changes.

concepts/imports_concept/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def function():
2+
print("function called ")
3+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# import module101.function as func1
2+
from module101 import function
3+
4+
function()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from .module201 import function1
2+
from concepts.imports_concept.package1.module101 import funciton1

concepts/imports_concept/package2/module202.py

Whitespace-only changes.

concepts/input.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var1 = int(input("enter age?"))
2+
3+
var2 = input("enter sex?")
4+
5+
print(type(var1), type(var2))

concepts/list_comprehension.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,6 @@
6161
print(r)
6262

6363
r = [(n1,n2) [n1 >n2] for n1,n2 in zip(a,b)]
64-
print(r)
64+
print(r)
65+
66+
#####################

concepts/loop/for.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Else would be executed after the for loop and would be skipped with break
2+
3+
#!/usr/bin/python3
4+
5+
numbers = [11,33,55,39,55,75,37,21,23,41,13,2]
6+
7+
for num in numbers:
8+
if num%2 == 0:
9+
print ('the list contains an even number')
10+
break
11+
else:
12+
print ('the list doesnot contain even number')
13+
14+
#############################################
15+
lst = range(2,15,2)
16+
# for a in lst:
17+
# print(a)
18+
19+
#############################################
20+
# print reverse of string
21+
str = "aseem jain is a good man"
22+
newstr = ""
23+
for i in range(len(str)):
24+
#print(str[i])
25+
newstr = newstr + str[i]
26+
print(newstr)
27+
28+
#############################################
29+
# iterating with index
30+
31+
for index in range(len(str)):
32+
print(str[index])
33+
34+
35+
#############################################
36+
37+
# iterating with index using enumerator
38+
colors = ["red", "green", "blue", "purple"]
39+
for index, color in enumerate(colors):
40+
print(f"{index} has {color}")
41+
42+
43+
#############################################
44+
45+
colors = ["red", "green", "blue", "purple"]
46+
ratios = [0.2, 0.3, 0.1, 0.4]
47+
sizes = ["xs", "s","m","l"]
48+
for color, ratio, size in zip(colors, ratios, sizes):
49+
print(color,ratio, size)

concepts/map_function.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717

1818
########################
1919
# creating a custom map
20+
# def my_map(f, lst):
21+
# for i in lst:
22+
# yield f(i)
23+
24+
# generator comprehension
2025
def my_map(f, lst):
21-
for i in lst:
22-
yield f(i)
26+
return (f(i) for i in lst)
2327

2428
o = my_map(str.capitalize, names)
2529
print(next(o))

concepts/mysql/prep_mode.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from optparse import OptionParser
2+
3+
prep_mode = None
4+
5+
parser = OptionParser()
6+
parser.add_option("-m", "--mode", dest="prep_mode", metavar="MYVAR",
7+
help="(REQUIRED)")
8+
9+
(options, args) = parser.parse_args()
10+
11+
print(options.prep_mode)
12+
prep_mode = options.prep_mode
13+
14+
if prep_mode is not None :
15+
print("only prepping")
16+
else:
17+
print("executing for real")
18+
File renamed without changes.
File renamed without changes.
File renamed without changes.

oop/Book.py concepts/oop/Book.py

File renamed without changes.
File renamed without changes.
File renamed without changes.

oop/DateTime.py concepts/oop/DateTime.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import datetime
44

55
t = datetime.time(5,25,1,44)
6-
print t
6+
print (t)
77

88
today=datetime.date.today()
99
d1 = datetime.date(25,2,2)
1010
d2 = datetime.date(5,2,2)
11-
print d1-d2
11+
print (d1-d2)
1212

File renamed without changes.

oop/Decorator.py concepts/oop/Decorator.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
def interceptor(func):
44

55
def wrapper_func():
6-
print "code before call of func"
6+
print "code before call of function"
77
func()
8-
print "code after call of func"
8+
print "code after call of function"
99
return wrapper_func
1010

1111
def wrapper_func(func):
12-
print "code before call of func"
12+
print "code before call of function"
1313
func()
14-
print "code after call of func"
14+
print "code after call of function"
1515
return wrapper_func
1616

1717

File renamed without changes.
File renamed without changes.

oop/Enumarate.py concepts/oop/Enumarate.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
list = [2,2.2,0," " ]
44
count = 0
55
for item in list :
6-
print "index "+ str(count) +" has element ",
7-
print item
6+
print ("index "+ str(count) +" has element ")
7+
print (item)
88
count+=1
99

1010
for index,item in enumerate(list):
1111
if index >2 : break;
1212
print( index , item)
1313

14-
lst = [2==2,2==3,4%2==0]
15-
print all(list)
14+
lst = [2==2,3==3,4%2==0]
15+
print (all(list))
1616

17-
print complex(1,2)
17+
print (complex(1,2))
1818
er = complex('2+2j')
19-
print er
19+
print (er)
2020

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

oop/scope.py concepts/oop/scope.py

File renamed without changes.

concepts/switch_case_simulation.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# switch of choice and case of grade assignment
2-
choice = 85
2+
choice = 90
33
try:
4-
grade= {90:"a",80:"b", 70:"c" } [choice]
4+
grade= {90:print("ais win"),80:"b", 70:"c" } [choice]
55
except:
66
grade ="unknown"
77
print(grade)
@@ -12,5 +12,5 @@
1212
print("max")
1313

1414
marks=99
15-
result = ("Fail","Pass") [marks > 70]
16-
print(result)
15+
result = ("Fail", "Pass")[marks > 70]
16+
print(result)

0 commit comments

Comments
 (0)