diff --git a/Section_01/assignment_01.py b/Section_01/assignment_01.py index 96bb182..fa1f33a 100644 --- a/Section_01/assignment_01.py +++ b/Section_01/assignment_01.py @@ -37,6 +37,9 @@ + + + diff --git a/Section_01/assignment_02.py b/Section_01/assignment_02.py index 3dc49a2..a5636d1 100644 --- a/Section_01/assignment_02.py +++ b/Section_01/assignment_02.py @@ -10,3 +10,15 @@ """ + + + + + + + + + + + + diff --git a/Section_01/assignment_03.py b/Section_01/assignment_03.py index 637873b..5d312a7 100644 --- a/Section_01/assignment_03.py +++ b/Section_01/assignment_03.py @@ -44,6 +44,10 @@ + + + + diff --git a/Section_01/assignment_04.py b/Section_01/assignment_04.py index 956262e..addb148 100644 --- a/Section_01/assignment_04.py +++ b/Section_01/assignment_04.py @@ -47,6 +47,10 @@ + + + + diff --git a/Section_02/assignment_01.py b/Section_02/assignment_01.py index 07bf2c7..742cfa9 100644 --- a/Section_02/assignment_01.py +++ b/Section_02/assignment_01.py @@ -37,6 +37,10 @@ + + + + diff --git a/Section_02/assignment_02.py b/Section_02/assignment_02.py index 26e017b..da7812a 100644 --- a/Section_02/assignment_02.py +++ b/Section_02/assignment_02.py @@ -40,6 +40,17 @@ + + + + + + + + + + + diff --git a/Section_02/assignment_03.py b/Section_02/assignment_03.py index aee6b05..5e91adb 100644 --- a/Section_02/assignment_03.py +++ b/Section_02/assignment_03.py @@ -39,6 +39,15 @@ + + + + + + + + + diff --git a/Section_02/assignment_04.py b/Section_02/assignment_04.py index 534a746..c3e2a50 100644 --- a/Section_02/assignment_04.py +++ b/Section_02/assignment_04.py @@ -7,8 +7,13 @@ my_list = [(1, 2), (3, 4), (['c', 'd', 'a', 'm'], [3, 9, 4, 12], 4), 'TV', 42] -my_list[2][0][3] = 'x' -my_list[3] = 'Television' +# Your Code Below: + + + + + + print(my_list) @@ -23,6 +28,27 @@ + + + + + + + + + + + + + + + + + + + + + # Solution: # my_list[2][0][3] = 'x' # my_list[3] = 'Television' diff --git a/Section_03/assignment_01.py b/Section_03/assignment_01.py index 8b6564a..3688656 100644 --- a/Section_03/assignment_01.py +++ b/Section_03/assignment_01.py @@ -7,10 +7,12 @@ # your code below: -def merge_lists(list_a, list_b): - return list_a + list_b -print(merge_lists([1,2,3,4], ['a','b','c'])) + + + + + diff --git a/Section_03/assignment_02.py b/Section_03/assignment_02.py index 67d82d0..3e74ab6 100644 --- a/Section_03/assignment_02.py +++ b/Section_03/assignment_02.py @@ -7,10 +7,18 @@ Make sure to test the function. """ # Your Code Below: -def separate(str): - return list(str) -print(separate("hello there")) + + + + + + + + + + + diff --git a/Section_03/assignment_03.py b/Section_03/assignment_03.py index ee5b370..0d9731f 100644 --- a/Section_03/assignment_03.py +++ b/Section_03/assignment_03.py @@ -10,10 +10,21 @@ """ # Your Code Below: -def multi_merge(list_a, str): - return list_a + str.split() + list(str) -print(multi_merge([1,2,3,4], "Hello My name is imtiaz")) + + + + + + + + + + + + + + diff --git a/Section_03/assignment_04.py b/Section_03/assignment_04.py index 530a070..a33876f 100644 --- a/Section_03/assignment_04.py +++ b/Section_03/assignment_04.py @@ -14,11 +14,15 @@ # Your code below: -def last_list(*args): - return args[-1] -print(last_list([1,2,3,4,5], ['a', 'b', 'c'], ['mike', 'john'])) + + + + + + + diff --git a/Section_03/assignment_05.py b/Section_03/assignment_05.py index 8f5663e..425df0b 100644 --- a/Section_03/assignment_05.py +++ b/Section_03/assignment_05.py @@ -15,13 +15,18 @@ # Your Code Below: -def key_list_items(key, **kwargs): - value_list = kwargs[key] - return value_list[-2] -result = key_list_items("things", things=['book', 'tv', 'shoes'], people=['pete', 'mike', 'jan', 'tom'], - ages=[20, 30, 40]) -print(result) + + + + + + + + + + + diff --git a/Section_04/assignment_01.py b/Section_04/assignment_01.py index abf45ed..f3313a1 100644 --- a/Section_04/assignment_01.py +++ b/Section_04/assignment_01.py @@ -12,8 +12,17 @@ """ -def twelver(a, b): - return (a == 12 or b == 12 or a+b == 12) +# Your Code Below: + + + + + + + + + + diff --git a/Section_04/assignment_02.py b/Section_04/assignment_02.py index 10f2464..d0dc7b5 100644 --- a/Section_04/assignment_02.py +++ b/Section_04/assignment_02.py @@ -17,8 +17,15 @@ pay_extra(True, 6) -> true """ -def pay_extra(working, hour): - return (working and (hour < 8 or hour > 20)) +# Your Code Below: + + + + + + + + diff --git a/Section_04/assignment_03.py b/Section_04/assignment_03.py index e194fe7..6d4d390 100644 --- a/Section_04/assignment_03.py +++ b/Section_04/assignment_03.py @@ -11,14 +11,13 @@ sequence([]) → False """ -def sequence(num_list): - for i in range(len(num_list)-2): - if num_list[i] == 1 and num_list[i+1] == 2 and num_list[i+2] == 3: - return True +# Your Code Below: + + + + - return False -print(sequence([])) diff --git a/Section_04/assignment_04.py b/Section_04/assignment_04.py index ba5d7ce..b5940c4 100644 --- a/Section_04/assignment_04.py +++ b/Section_04/assignment_04.py @@ -9,16 +9,14 @@ """ -def grow_string(str): +# Your Code Below: + + + - result = "" - for i in range(len(str)): - result = result + str[:i + 1] - return result -print(grow_string("Imtiaz")) diff --git a/Section_04/assignment_05.py b/Section_04/assignment_05.py index 5a6f98d..3b61d70 100644 --- a/Section_04/assignment_05.py +++ b/Section_04/assignment_05.py @@ -13,19 +13,12 @@ """ -def first3(numbers): +# Your Code Below: + - end = len(numbers) - if end > 4: - end = 4 - for i in range(end): # loop over index 0,1,2,3 - if numbers[i] == 6: - return True - # if we get here, the loop is over and we didn't find a 6 - return False print(first3([1,2,6,3,0,0])) # true diff --git a/Section_04/assignment_06.py b/Section_04/assignment_06.py index 96b31e8..8219b61 100644 --- a/Section_04/assignment_06.py +++ b/Section_04/assignment_06.py @@ -16,21 +16,8 @@ """ -def last2(str): +# Your Code Below: - if len(str) <= 2: - return 0 - - # last 2 chars can also be extracted with str[-2:] - last2 = str[len(str) - 2:] - count = 0 - - for i in range(len(str) - 2): - sub = str[i : i+2] - if sub == last2: - count = count + 1 - - return count print(last2('hixxhi')) #→ 1 @@ -53,6 +40,11 @@ def last2(str): + + + + + diff --git a/Section_04/assignment_07.py b/Section_04/assignment_07.py index 07c878a..32484a0 100644 --- a/Section_04/assignment_07.py +++ b/Section_04/assignment_07.py @@ -12,20 +12,7 @@ """ -def string_match(a, b): - - # Figure out which string is shorter - shorter = min(len(a), len(b)) - - count = 0 - - for i in range(shorter - 1): - a_sub = a[i: i+2] # gives us substring of size 2 - b_sub = b[i: i+2] - if a_sub == b_sub: - count = count + 1 - - return count +#Your Code Below: diff --git a/Section_04/assignment_08.py b/Section_04/assignment_08.py index e8cbbf6..49ebe3d 100644 --- a/Section_04/assignment_08.py +++ b/Section_04/assignment_08.py @@ -14,24 +14,22 @@ """ -def sum78(nums): +#Your Code Below: + + + + + + + + + - sum = 0 - in_range = False - for i in range(len(nums)): - if nums[i] == 7: - in_range = True - if in_range == False: - # sum = sum + nums[i] - sum += nums[i] - if nums[i] == 8: - in_range = False - return sum print(sum78([1, 2, 2])) #→ 5 diff --git a/Section_04/Assignment_09.py b/Section_04/assignment_09.py similarity index 78% rename from Section_04/Assignment_09.py rename to Section_04/assignment_09.py index 488f886..d3150d2 100644 --- a/Section_04/Assignment_09.py +++ b/Section_04/assignment_09.py @@ -36,31 +36,15 @@ } -# Your Code below: +# Your Code Below: # -------------------------------------- -line_list = [] -for line in fr: - columns = line.split("|") - lookup_val = columns[0] - # if lookup_val not in d.keys(): - if(d.get(lookup_val) is None): # Can't find email in dict - next_number = int(max(d.values())) + 1 - d[lookup_val] = str(next_number) - columns[0] = str(next_number) - line_list.append("|".join(columns)) - else: # we were able to find email in dictionary - columns[0] = d.get(lookup_val) - line_list.append("|".join(columns)) -fr = line_list - - -# don't change the below: +# don't change the lines below: # -------------------------------------- print("Value of fr: ") print(fr) @@ -82,6 +66,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + # Solution: # # line_list = [] diff --git a/Section_05/assignment_01.py b/Section_05/assignment_01.py index 6f45f12..3e8762f 100644 --- a/Section_05/assignment_01.py +++ b/Section_05/assignment_01.py @@ -12,60 +12,112 @@ dog, fish and bird and make them eat and move. """ +# Your Code Below: -class Animal: - def __init__(self): - print("Animal Constructed") - def move(self): - print("Animal Moving...") - def eat(self): - print("Animal Eating...") -class Bird(Animal): - def __init__(self, bird_age, bird_name): - Animal.__init__(self) - self.age = bird_age - self.name = bird_name - def move(self): - print("Bird flying...") -class Fish(Animal): - def __init__(self, bird_age, bird_name): - Animal.__init__(self) - self.age = bird_age - self.name = bird_name - def move(self): - print("Fish Swimming...") -class Dog(Animal): - def __init__(self, bird_age, bird_name): - Animal.__init__(self) - self.age = bird_age - self.name = bird_name - def move(self): - print("Dog Running ...") -mydog = Dog(3, "wolfy") -mydog.move() -mydog.eat() -mydog = Fish(1, "nemo") -mydog.move() -mydog.eat() -mydog = Bird(3, "jojo") -mydog.move() -mydog.eat() \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +# Solution: +# class Animal: +# def __init__(self): +# print("Animal Constructed") +# +# def move(self): +# print("Animal Moving...") +# +# def eat(self): +# print("Animal Eating...") +# +# +# +# class Bird(Animal): +# +# def __init__(self, bird_age, bird_name): +# Animal.__init__(self) +# self.age = bird_age +# self.name = bird_name +# +# def move(self): +# print("Bird flying...") +# +# +# +# class Fish(Animal): +# +# def __init__(self, bird_age, bird_name): +# Animal.__init__(self) +# self.age = bird_age +# self.name = bird_name +# +# def move(self): +# print("Fish Swimming...") +# +# +# class Dog(Animal): +# +# def __init__(self, bird_age, bird_name): +# Animal.__init__(self) +# self.age = bird_age +# self.name = bird_name +# +# def move(self): +# print("Dog Running ...") +# +# mydog = Dog(3, "wolfy") +# mydog.move() +# mydog.eat() +# +# mydog = Fish(1, "nemo") +# mydog.move() +# mydog.eat() +# +# mydog = Bird(3, "jojo") +# mydog.move() +# mydog.eat() \ No newline at end of file diff --git a/Section_06/assignment_01.py b/Section_06/assignment_01.py index c6ab6dd..10583e5 100644 --- a/Section_06/assignment_01.py +++ b/Section_06/assignment_01.py @@ -12,21 +12,68 @@ # Expected Output: # {"there": n, "Michael": n, "running": n} -words_and_counts = {} +# Your Code Below: -for word in words_to_aggregate: - count = 0 - for path, folder_names, file_names in os.walk(directory_containing_files): - for file_name in file_names: - file = os.path.join(path, file_name) - with open(file, "r") as a_file: - for line in a_file: - if re.search(word, line): - word_list = re.findall(word, line) - count += len(word_list) - words_and_counts[word] = count -print(words_and_counts) \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#Solution: +# words_and_counts = {} +# +# for word in words_to_aggregate: +# count = 0 +# for path, folder_names, file_names in os.walk(directory_containing_files): +# for file_name in file_names: +# file = os.path.join(path, file_name) +# with open(file, "r") as a_file: +# for line in a_file: +# if re.search(word, line): +# word_list = re.findall(word, line) +# count += len(word_list) +# +# words_and_counts[word] = count +# +# +# +# print(words_and_counts) \ No newline at end of file