Skip to content
Course Notes
Use this workspace to take notes, store code snippets, or build your own interactive cheatsheet! For courses that use data, the datasets will be available in the datasets
folder.
# Import any packages you want to use here
Take Notes
Add notes here about the concepts you've learned and code cells with code you want to keep.
Add your notes here
# Add your code snippets here
# Find characters in movie variable
length_string = len(movie)
# Convert to string
to_string = str(length_string)
# Predefined variable
statement = "Number of characters in this review:"
# Concatenate strings and print result
print(statement +" "+ to_string)
# Select the first 32 characters of movie1
first_part = movie1[:32]
# Select from 43rd character to the end of movie1
last_part = movie1[42:]
# Select from 33rd to the 42nd character
middle_part = movie2[32:42]
# Print concatenation and movie2 variable
print(first_part+middle_part+last_part)
print(movie2)
# Get the word
movie_title = movie[11:30]
# Obtain the palindrome
palindrome = movie_title[::-1]
# Print the word if it's a palindrome
if movie_title == palindrome:
print(movie_title)
# Convert to lowercase and print the result
movie_lower = movie.lower()
print(movie_lower)
# Remove specified character and print the result
movie_no_sign = movie_lower.strip("$")
print(movie_no_sign)
# Split the string into substrings and print the result
movie_split = movie_no_sign.split()
print(movie_split)
# Select root word and print the result
word_root = movie_split[1][0:-1]
print(word_root)
# Remove tags happening at the end and print results
movie_tag = movie.rstrip("<\i>")
print(movie_tag)
# Split the string using commas and print results
movie_no_comma = movie_tag.split(",")
print(movie_no_comma)
# Join back together and print results
movie_join = " ".join(movie_no_comma)
print(movie_join)
# Split string at line boundaries
file_split = file.split("\n")
# Print file_split
print(file_split)
# Complete for-loop to split by commas
for substring in file_split:
substring_split = substring.split(',')
print(substring_split)
for movie in movies:
# If actor is not found between character 37 and 41 inclusive
# Print word not found
if movie.find("actor", 37, 42) == -1:
print("Word not found")
# Count occurrences and replace two with one
elif movie.count("actor") == 2:
print(movie.replace("actor actor", "actor"))
else:
# Replace three occurrences with one
print(movie.replace("actor actor actor", "actor"))
for movie in movies:
try:
# Find the first occurrence of word
print(movie.index("money", 12, 51))
except ValueError:
print("substring not found")
# Replace negations
movies_no_negation = movies.replace("isn't", "is")
# Replace important
movies_antonym = movies_no_negation.replace("important", "insignificant")
# Print out
print(movies_antonym)
# Assign the substrings to the variables
first_pos = wikipedia_article[3:19].lower()
second_pos = wikipedia_article[21:44].lower()
# Define string with placeholders
my_list.append("The tool {} is used in {}")
# Define string with rearranged placeholders
my_list.append("The tool {1} is used in {0}")
# Use format to print strings
for my_string in my_list:
print(my_string.format(first_pos, second_pos))
courses = ['artificial intelligence', 'neural networks']
# Create a dictionary
plan = {
"field": courses[0],
"tool": courses[1]
}
# Complete the placeholders accessing elements of field and tool keys in the data dictionary
my_message = "If you are interested in {data[field]}, you can take the course related to {data[tool]}"
# Use the plan dictionary to replace placeholders
print(my_message.format(data=plan))