diff --git a/Week2 _hmwrk_1 copy.py b/Week2 _hmwrk_1 copy.py new file mode 100644 index 0000000..5cfaadf --- /dev/null +++ b/Week2 _hmwrk_1 copy.py @@ -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)) diff --git a/Week2 _hmwrk_1.py b/Week2 _hmwrk_1.py new file mode 100644 index 0000000..5cfaadf --- /dev/null +++ b/Week2 _hmwrk_1.py @@ -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)) diff --git a/Week2_hmwrk_2 copy.py b/Week2_hmwrk_2 copy.py new file mode 100644 index 0000000..f54ddcf --- /dev/null +++ b/Week2_hmwrk_2 copy.py @@ -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) diff --git a/Week2_hmwrk_2.py b/Week2_hmwrk_2.py new file mode 100644 index 0000000..f54ddcf --- /dev/null +++ b/Week2_hmwrk_2.py @@ -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) diff --git a/Week2_hmwrk_3 copy.py b/Week2_hmwrk_3 copy.py new file mode 100644 index 0000000..62b062d --- /dev/null +++ b/Week2_hmwrk_3 copy.py @@ -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'] \ No newline at end of file diff --git a/Week2_hmwrk_3.py b/Week2_hmwrk_3.py new file mode 100644 index 0000000..43c0c25 --- /dev/null +++ b/Week2_hmwrk_3.py @@ -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")) \ No newline at end of file