This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| def multi_vowel_words(text): | |
| pattern = r"(\w+[a,e,i,o,u]{3,}\w+)" | |
| result = re.findall(pattern, text) | |
| return result | |
| print(multi_vowel_words("Life is beautiful")) | |
| # ['beautiful'] | |
| print(multi_vowel_words("Obviously, the queen is courageous and gracious.")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| def check_time(text): | |
| pattern = r"[1-9][0-2]?:[0-5][0-9] ?[am|pm|AM|PM]" | |
| result = re.search(pattern, text) | |
| return result != None | |
| print(check_time("12:45pm")) # True | |
| print(check_time("9:59 AM")) # True | |
| print(check_time("6:60am")) # False | |
| print(check_time("five o'clock")) # False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def count_letters(text): | |
| result = {} | |
| text = text.lower() | |
| # Go through each letter in the text | |
| for letter in text: | |
| # Check if the letter needs to be counted or not | |
| if letter .isalpha() and letter not in result: | |
| result[letter] = text.lower().count(letter) | |
| # Add or increment the value in the dictionary | |
| return result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def is_palindrome(input_string): | |
| # We'll create two strings, to compare them | |
| new_string = "" | |
| reverse_string = "" | |
| # Traverse through each letter of the input string | |
| for string in input_string.lower(): | |
| # Add any non-blank letters to the | |
| # end of one string, and to the front | |
| # of the other string. | |
| if string.replace(" ",""): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import datetime | |
| def file_date(filename): | |
| # Create the file in the current directory | |
| with open (filename,'w') as file: | |
| pass | |
| timestamp = os.path.getmtime(filename) | |
| c=datetime.datetime.fromtimestamp(timestamp) | |
| # Convert the timestamp into a readable format, then into a string |