How Do You Write a Python Program to Find if The “Read more” Preview on a Web Page is Visible for Every Web Page Previewed?

Problem scenario
Sometimes the “Read more” or “Continue reading” hyperlink in the page preview of your website (e.g., when you search for a word), is not visible. You know that some of your web page previews on your website don’t have the “Read more” hyperlink at the end. This makes the preview appear to have the entire web page. You need to identify the postings that don’t have the “Read more.” How do you use Python to find the pages that have previews that have no “Read more” hyperlink?

How Do You Write a Python Function to Determine if There Are Three or More Unique Characters in a String?

Problem scenario
You want a function to tell you if there are three unique characters in a string. For example “ababababa” would have fewer than three unique characters. But “abc” would have three or more unique characters. How do you write a function that does this that solves in linear time?

Solution

variable_to_test = “aaaaaaaaaaaabbbbbb”

def two_unique(s):
flag = “There are only two unique characters in the string!”
dict_a = {}
for string_portion in s:
if string_portion in dict_a:
pass
else:
dict_a[string_portion] = 1
key_counter = 0
for key in dict_a.keys():
key_counter = key_counter + 1; …

Why Are Python List Operations/Methods Unlike Python String Operations/Methods?

Problem scenario
List operations such as .sort() will change previous copies of the list.

String operations such as .replace(“old_pattern”, “new_pattern”, count), will not change the variable or its copies; these operations will return a string after the replace operation has run on the original string.

Why is this behavior happening?

Solution
In-place changes and mutability are factors. Strings are generally immutable whereas copies of lists are usually shallow.

How Do You Troubleshoot “SyntaxError: invalid syntax” in Python?

Problem scenario
You are running a Python script. You keep getting “SyntaxError: invalid syntax” and a line number. You can find nothing wrong with the syntax on the specified line number. What do you do?

Possible solution #1
Look at the line with code, as opposed to blank line(s), above it. Is there a missing quote, brace, bracket or parentheses?

Possible solution #2
Are you trying to use an “if” statement on one line?

How Do You Close Your Apple ID Account?

Problem scenario
You have an iCloud, iTunes, iMessage, FaceTime, or some other Apple account online. You want to cancel your account and destroy or delete the data. What do you do?

Solution
1. Log into your Apple.com account (e.g., https://appleid.apple.com/#!&page=signin).
2. Go here: https://privacy.apple.com/
3. Go to “Request to delete your account”
4. Follow the prompts.

How Do You Pass Two or More Subnets to an “aws eks” Command?

Problem scenario
You want to pass more than one subnet to an “aws eks” command.

You tried to delimit the list with commas (or separate two subnet IDs with commas). You received this error message:

An error occurred (InvalidParameterException) when calling the CreateNodegroup operation: The subnet ID ‘subnet-0abcd1234,subnet-zyxw9876’ does not exist (Service: AmazonEC2; Status Code: 400; Error Code: InvalidSubnetID.NotFound; Request ID: Proxy: null)

What should you do?