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
11 changes: 11 additions & 0 deletions Week2 _hmwrk_1 copy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def shift_list(list_, a):
if a >= 0:
return list_[-a:] + list_[:-a]
else:
a = abs(a)
return list_[a:] + list_[:a]

#Check the function
check_func = ['a', 'b', 'c', 'd', 'e', 'f']
print(shift_list(check_func, 4))
print(shift_list(check_func, -4))
11 changes: 11 additions & 0 deletions Week2 _hmwrk_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def shift_list(list_, a):
if a >= 0:
return list_[-a:] + list_[:-a]
else:
a = abs(a)
return list_[a:] + list_[:a]

#Check the function
check_func = ['a', 'b', 'c', 'd', 'e', 'f']
print(shift_list(check_func, 4))
print(shift_list(check_func, -4))
21 changes: 21 additions & 0 deletions Week2_hmwrk_2 copy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
text = input("Enter a text: ")

# creating an empty dictionary to store letter counts
letter_counts = {}

# For loop and iterate through each letter in the text
for letter in text:
# ignore spaces and convert letter to lowercase
if letter != ' ':
letter = letter.lower()
# if the letter is already in the dictionary, increase the counting
if letter in letter_counts:
letter_counts[letter] += 1
# or else, add the letter to the dictionary with a count of 1
else:
letter_counts[letter] = 1

# items() for getting the elemnets as pairs, sort() for getting the alphabetic order
letter_counts_list = list(letter_counts.items())
letter_counts_list.sort()
print(letter_counts_list)
21 changes: 21 additions & 0 deletions Week2_hmwrk_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
text = input("Enter a text: ")

# creating an empty dictionary to store letter counts
letter_counts = {}

# For loop and iterate through each letter in the text
for letter in text:
# ignore spaces and convert letter to lowercase
if letter != ' ':
letter = letter.lower()
# if the letter is already in the dictionary, increase the counting
if letter in letter_counts:
letter_counts[letter] += 1
# or else, add the letter to the dictionary with a count of 1
else:
letter_counts[letter] = 1

# items() for getting the elemnets as pairs, sort() for getting the alphabetic order
letter_counts_list = list(letter_counts.items())
letter_counts_list.sort()
print(letter_counts_list)
10 changes: 10 additions & 0 deletions Week2_hmwrk_3 copy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def shared_letters(w1, w2):
set1 = set(w1)
set2 = set(w2)
shared = set1 & set2 # intersection
unique1 = set1 - set2 # difference
unique2 = set2 - set1 # difference
return [''.join(sorted(shared)), ''.join(sorted(unique1)), ''.join(sorted(unique2))]

# test the function
print(shared_letters("strong", "strength")) # ['strng', 'o', 'eh']
9 changes: 9 additions & 0 deletions Week2_hmwrk_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def shared_letters(w1, w2):
set1 = set(w1)
set2 = set(w2)
shared = set1 & set2 # intersection
unique1 = set1 - set2 # difference
unique2 = set2 - set1 # difference
return [''.join(sorted(shared)), ''.join(sorted(unique1)), ''.join(sorted(unique2))]

print(shared_letters("strong", "strength"))