This Python script is designed to parse text for hexadecimal color codes. Hexadecimal color codes are commonly used in web development and design to specify colors. These codes start with a '#' symbol and are followed by six or three hexadecimal digits (0-9, A-F). The script reads a number 'n' from the user, then reads 'n' lines of text, and searches each line for these color codes.
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 Python's built-in 're' module for regular expression matching. It defines a regular expression that matches either a three-digit or a six-digit hexadecimal color code, followed by a non-alphanumeric character (to ensure the color code is not part of a larger string). The 'findall' function is used to find all matches in each line of text. If a match is found, it is printed to the console. The script repeats this process for each line of text.
import re
n = int(input())
for _ in range(n):
s = input()
match_result = re.findall(r"(#[0-9A-Fa-f]{3}|#[0-9A-Fa-f]{6})(?:[;,.)]{1})", s)
for i in match_result:
if i != "":
print(i)
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.