The script reads from a file named 'python_info.txt', which contains the names of problems and their respective subdomains. It then generates a list of these problems and writes them into an HTML file named 'solution_list.html'. The script also handles the formatting of the problem names and subdomain names to ensure they are valid for use in file paths.
CodeRankGPT is a tool powered by GPT-4 that quietly assists you during your coding interview, providing the solutions you need.
In real-time and absolutely undetectable 🥷
The script uses the built-in Python libraries 'os', 're', and 'sys'. It reads from an input file line by line, and for each line, it checks if it is a problem name or a subdomain name. If it is a problem name, it is added to the problem list. If it is a subdomain name, it is stored as the current subdomain. When both a problem and a subdomain have been found, the script generates a valid folder name from the subdomain name, finds all the titles in the problem list, and writes them into the output HTML file with the appropriate file path. The script continues this process until it has processed all lines in the input file.
import os
import re
import sys
info_file_name = "python_info.txt"
def get_valid_name(given_name):
return re.sub(r"[^\w]", "", given_name)
problem_list = ""
subdomain_name = ""
extension = ".py"
info_file = open(info_file_name, "r")
info_file_lines = info_file.readlines()
info_file.close()
output_file_name = "solution_list.html"
f = open(output_file_name, "w")
f.write("\n")
for line in info_file_lines:
line = line.strip()
if line == "":
continue
elif line[0] == "[":
problem_list = line
else:
subdomain_name = line
if subdomain_name != "" and problem_list != "":
folder_name = get_valid_name(subdomain_name)
title_ar = re.findall(r'("[^"]*")', problem_list)
title_ar_len = len(title_ar)
f.write("- " + subdomain_name + "\n")
for title in title_ar:
filename = get_valid_name(title[1:-1])
filepath = folder_name + "/" + filename + extension
f.write(" - [" + title[1:-1] + "](" + filepath + ")\n")
subdomain_name = ""
problem_list = ""
f.close()
print("List generated successfully. Open " + output_file_name + " to view.")
If you have a HackerRank coding test coming up, you can use CodeRankGPT to your advantage. It will assist you during your interview and help ensure you get the job.
AI is here now, and other candidates might be using it to get ahead and win the job. 🧐
The form has been successfully submitted.