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 repeating_letter_a(text): | |
result = re.search(r"[Aa].*a", text) | |
return result != None | |
print(repeating_letter_a("banana")) # True | |
print(repeating_letter_a("pineapple")) # False | |
print(repeating_letter_a("Animal Kingdom")) # True | |
print(repeating_letter_a("A is for apple")) # True |
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_punctuation (text): | |
result = re.search(r"[,.:;?!]", text) | |
return result != None | |
print(check_punctuation("This is a sentence that ends with a period.")) # True | |
print(check_punctuation("This is a sentence fragment without a period")) # False | |
print(check_punctuation("Aren't regular expressions awesome?")) # True | |
print(check_punctuation("Wow! We're really picking up some steam now!")) # True | |
print(check_punctuation("End of the line")) # 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
import os | |
import csv | |
# Create a file with data in it | |
def create_file(filename): | |
with open(filename, "w") as file: | |
file.write("name,color,type\n") | |
file.write("carnation,pink,annual\n") | |
file.write("daffodil,yellow,perennial\n") | |
file.write("iris,blue,perennial\n") |
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 csv | |
# Create a file with data in it | |
def create_file(filename): | |
with open(filename, "w") as file: | |
file.write("name,color,type\n") | |
file.write("carnation,pink,annual\n") | |
file.write("daffodil,yellow,perennial\n") | |
file.write("iris,blue,perennial\n") |
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 | |
def parent_directory(): | |
# Create a relative path to the parent | |
# of the current working directory | |
dir = os.getcwd() | |
relative_parent = os.path.join(dir) | |
os.chdir("..") | |
# Return the absolute path of the parent directory | |
return os.path.abspath(relative_parent) |
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) | |
# Convert the timestamp into a readable format, then into a string | |
date = datetime.datetime.fromtimestamp(timestamp).date() |
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 | |
def new_directory(directory, filename): | |
# Before creating a new directory, check to see if it already exists | |
if os.path.isdir(directory) == False: | |
os.makedirs(directory, exist_ok=True) | |
# Create the new file inside of the new directory | |
os.chdir(directory) | |
with open (filename, "w") as file: |
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 | |
def create_python_script(filename): | |
comments = "# Start of a new Python program" | |
with open("filename", 'w') as f: | |
filesize = f.write(comments) | |
return(filesize) | |
print(create_python_script("program.py")) |
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 highlight_word(sentence, word): | |
return(sentence.replace(word,word.upper())) |
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 format_address(address_string): | |
# Declare variables | |
house_number = 0 | |
street_name = [] | |
# Separate the address string into parts | |
address = address_string.split() | |
# Traverse through the address parts | |
for item in address: | |
if item.isnumeric(): | |
house_number = item |