Holy crap! I just asked the ChatGPT to write a Python script and it did! Plus it gave example output and summarized the code in plain (techie) language.
Me:
Create a Python script that takes a 2 dimensional array of text strings (with the array being a list of Given name strings and Surname strings) that prints the Strings in list order with a superscript list item index between each Given name and Surname and semicolons separating each element of the list. Surnames should be in Small Caps format.
It responds:
Certainly! Here’s a Python script that takes a 2-dimensional array of text strings, where each sub-array contains a Given name and Surname, and prints the strings in list order with a superscript list item index between each Given name and Surname, and semicolons separating each element of the list. Surnames are printed in Small Caps format:
def print_name_list(arr):
for i, name in enumerate(arr):
given_name, surname = name
if i == len(arr) - 1:
print(f"{given_name}{superscript(i)} {small_caps(surname)}")
else:
print(f"{given_name}{superscript(i)} {small_caps(surname)}; ", end="")
def superscript(num):
superscript_chars = str.maketrans("0123456789", "⁰¹²³⁴⁵⁶⁷⁸⁹")
return str(num).translate(superscript_chars)
def small_caps(text):
small_caps_chars = str.maketrans("abcdefghijklmnopqrstuvwxyz", "ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ")
return text.translate(small_caps_chars)
# Example usage
arr = [["Alice", "SMITH"], ["Bob", "JONES"], ["Charlie", "JOHNSON"]]
print_name_list(arr)
This will output:
Alice⁰ Sᴍɪᴛʜ; Bob¹ Jᴏɴᴇs; Charlie² Jᴏʜɴsᴏɴ
In this example, print_name_list()
takes a 2-dimensional array of text strings (arr
) as input, where each sub-array contains a Given name and Surname. For each name in the array, it prints the Given name with a superscript list item index using the superscript()
function, followed by the Surname in Small Caps format using the small_caps()
function.
The superscript()
function is the same as in the previous example, and the small_caps()
function takes a string as input and returns a new string where each character is replaced by the corresponding Small Caps character.
The print_name_list()
function uses the end
parameter in the print()
function to print each name and superscript index with a semicolon and space separator ("; "), except for the last element, which is printed without a separator.