How Do You Write a Flask Program to Accept a Parameter in the URL?

Problem scenario
You want to pass a variable via a URL to a Python program. You want to use Flask for this. What do you do?

Solution
Prerequisite

Install Flask. If you need assistance, see this posting if you are using a CentOS/RHEL/Fedora server or this posting if you are using a Debian/Ubuntu server.

Procedures
This is a multi-route Flask program.

How Do You Sort a Dictionary in Python and Use It?

Problem scenario
You want to use a sorted dictionary in Python. What do you do?

Solution
Create a sorted list based on the dictionary’s keys. Use the list as keys to summon the dictionary’s values.

contint_dict = {}
contint_dict[”a_test”] = “123”
contint_dict[”b_test”] = “456”
contint_dict[”c_test”] = “789”
sorted_dict_list = sort1ed(contint_dict.items()) # sorted_dict_list is a list, not a dictionary.
list_of_keys = sorted(contint_dict.keys())

for key_pair in sorted_dict_list:
print(key_pair)

print(“”)
print(“Above are key-pairs. …

How Do You Troubleshoot the Flask Message “LookupError: the converter ‘str’ does not exist”?

Problem scenario
You are trying to pass a string parameter to a Flask application via a call to a URL. You get the message “LookupError: the converter ‘str’ does not exist.” What should you do?

Solution
Use the term “string” instead of “str”.

Here is an example of incorrect syntax:
@app.route(“/ccc/”, strict_slashes=False)

This shows the correct syntax:
@app.route(“/ccc/”,

How Do You Use a Nested Dictionary in Python?

Problem scenario
You want to create a dictionary of dictionaries in Python. You want to use them. What do you do?

Solution
Here is an example/illustration:

contint_dict = {}
contint_dict[”a_test”] = “123”
contint_dict[”b_test”] = “456”
contint_dict[”c_test”] = “789”

color_animal_dict = {}
color_animal_dict[”blue”] = “dog”
color_animal_dict[”orange”] = “cat”
color_animal_dict[”green”] = “goat”

days_dict = {}
days_dict[”Tuesday”] = “midnight”
days_dict[”Wednesday”] = “noon”
days_dict[”Thursday”] = “evening”

big_dictionary = {}
big_dictionary[”dict_1″] = contint_dict
big_dictionary[”dict_2″] = color_animal_dict
big_dictionary[”dict_3″] = days_dict

print(big_dictionary[”dict_1″][”b_test”])
print(big_dictionary[”dict_2″][”green”])
print(big_dictionary[”dict_3″][”Wednesday”])

super_dictionary = {}
super_dictionary[”top_of_nested”] = big_dictionary
print(super_dictionary[”top_of_nested”][”dict_3″][”Wednesday”])

You may also want to see this: https://pypi.org/project/nested_dict/

How Does sorted(list_arg1, key=arg2) Work in Python?

Question
You see that Python’s sorted reserved word has an option to use a key (rather than the default mechanism). How does the key parameter/flag in Python’s sorted function work?

Short Answer:
The word “key” designates a special function that you create. It accepts two parameters and returns positive or negative numbers. These help give you the ability to sort the list in a non-standard way.

How Do You Do a regex Operation in Python without Importing a Module?

Problem scenario
You need a pattern matching function in a Python program, but you cannot use “import re”. What should you do?

Possible Solution #1
Use the index() function.

Here is an example:

foobar = “abcdefghijklmnopqrstuvwxyz”
print(foobar.index(‘jk’))

Possible Solution #2
Use the .starswith() function.

foobar = “abcdefghijklmnopqrstuvwxyz”
print(foobar.startswith(‘abc’))

Possible Solution #3
Use the find() function.

How Do You Quickly Do Some Python Coding?

Problem scenario
You want to test some Python scripting or write a basic program to warm up before a coding interview. You only have access to a Windows machine (e.g., at a hotel “business center”). You cannot install Python on the laptop. How do you do some Python coding?

Solution
As long as you have access to the internet, browse to this site: https://www.onlinegdb.com/

(For a more serious development project,

How Do You Install Windows DSC on Windows Server 2019?

Problem scenario
You are running Windows Server 2019. You want to install Windows DSC. What do you do?

Solution

  1. Open PowerShell.
  2. Run this command: Install-Module ‘PSDscResources’ -Verbose
  3. When prompted with this question “NuGet provider is required to continue…”, choose “Yes”.
  4. If you believe your Windows Server is in a secure environment, or you have no goals putting sensitive data on your Windows server,