Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions week2_answer1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def shift(lis, n):

if 0<n<len(lis):
return lis[-1 * n:] + lis[:len(lis) - n]
elif -1>n> -1 * len(lis):
return lis[len(lis) + n - 1:] + lis[:n - 1]
else:
return lis

print(shift([1, 2, 3, 4, 5], -5))
13 changes: 13 additions & 0 deletions week2_answer2.py
Original file line number Diff line number Diff line change
@@ -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"))
21 changes: 21 additions & 0 deletions week2_answer3.py
Original file line number Diff line number Diff line change
@@ -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'))