diff --git a/week2_answer1.py b/week2_answer1.py new file mode 100644 index 0000000..1262aae --- /dev/null +++ b/week2_answer1.py @@ -0,0 +1,10 @@ +def shift(lis, n): + + if 0n> -1 * len(lis): + return lis[len(lis) + n - 1:] + lis[:n - 1] + else: + return lis + +print(shift([1, 2, 3, 4, 5], -5)) \ No newline at end of file diff --git a/week2_answer2.py b/week2_answer2.py new file mode 100644 index 0000000..5fb4e4a --- /dev/null +++ b/week2_answer2.py @@ -0,0 +1,13 @@ +def count_letters(text): + result = {} + text = text.lower() + # Go through each letter in the text + for i in text: + # Check if the i needs to be counted or not + if i.isalpha() : + # Add or increment the value in the dictionary + count = text.count(i) + result[i] = count + return result + +print(count_letters("This is a sample text")) diff --git a/week2_answer3.py b/week2_answer3.py new file mode 100644 index 0000000..fac803a --- /dev/null +++ b/week2_answer3.py @@ -0,0 +1,21 @@ +def Common_Uncommon_Words(str1, str2): + l1 = [] + l2 = [] + l3 = [] + for i in str1: + if (i in str2): + l1.append(i) + elif (i not in str2): + l2.append(i) + for j in str2: + if (j not in str1): + l3.append(j) + return [''.join(l1)] + [''.join(l2)] + [''.join(l3)] + + +print(Common_Uncommon_Words('sharp', 'soap')) + + + + +