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
Binary file added __pycache__/functions.cpython-312.pyc
Binary file not shown.
79 changes: 79 additions & 0 deletions functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@

import string


def get_unique_list_f(lst):
"""
Takes a list as an argument and returns a new list with unique elements from the first list.

Parameters:
lst (list): The input list.

Returns:
list: A new list with unique elements from the input list.
"""
# your code goes here
unique_list = []
for item in lst:
if item not in unique_list: # uniqueness check: if the item is already in unique_list, we skip it; if it’s not there yet, we accept it
unique_list.append(item)
return unique_list




def count_case_f(string):
"""
Returns the number of uppercase and lowercase letters in the given string.

Parameters:
string (str): The string to count uppercase and lowercase letters in.

Returns:
A tuple containing the count of uppercase and lowercase letters in the string.
"""
# your code goes here
upper_count = 0
lower_count = 0
for char in string:
if char.isupper():
upper_count += 1
elif char.islower():
lower_count += 1
return (upper_count, lower_count)



def remove_punctuation_f(sentence):
"""
Removes all punctuation marks (commas, periods, exclamation marks, question marks) from a sentence.

Parameters:
sentence (str): A string representing a sentence.

Returns:
str: The sentence without any punctuation marks.
"""
# your code goes here
punctuation_marks = string.punctuation # Get all standard punctuation marks
no_punct_sentence = ''.join(char for char in sentence if char not in punctuation_marks)
return no_punct_sentence




def word_count_f(sentence):
"""
Counts the number of words in a given sentence. To do this properly, first it removes punctuation from the sentence.
Note: A word is defined as a sequence of characters separated by spaces. We can assume that there will be no leading or trailing spaces in the input sentence.

Parameters:
sentence (str): A string representing a sentence.

Returns:
int: The number of words in the sentence.
"""
# your code goes here
no_punct_sentence = remove_punctuation_f(sentence)
words = no_punct_sentence.split() # Split the sentence into words based on spaces
return len(words)
Loading