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
57 changes: 57 additions & 0 deletions functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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.
"""
return list(set(lst))


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

Parameters:
input_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.
"""
uppercase_count = sum(1 for char in input_string if char.isupper())
lowercase_count = sum(1 for char in input_string if char.islower())
return (uppercase_count, lowercase_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.
"""
return sentence.translate(str.maketrans('', '', string.punctuation))


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.
"""
clean_sentence = remove_punctuation_f(sentence)
return len(clean_sentence.split())
Loading