HackerRank Hex Color Code solution in Python YASH PAL, 31 July 202417 January 2026 HackerRank Hex Color Code solution in Python – In this Hex Color Code problem in Python programming, you are given N lines of CSS code. Your task is to print all valid Hex Color Codes, in order of their occurrence from top to bottom.CSS colors are defined using a hexadecimal (HEX) notation for the combination of Red, Green, and Blue color values (RGB). Specifications of HEX Color Code■ It must start with a ‘#‘ symbol.■ It can have 3 or 6 digits.■ Each digit is in the range of 0 to F. (1,2,3,4,5,6,7,8,9,0,A,B,C,D,E and F).■ A – F letters can be lower case. (a,b,c,d,e and f are also valid digits).Examples Valid Hex Color Codes #FFF #025 #F0A1FB Invalid Hex Color Codes #fffabg #abcf #12365erffHackerRank Hex Color code solution in Python 2.import re reg1="{[^}]*}" reg2="""(#(?:[0-9A-Fa-f]){3}|#(?:[0-9A-Fa-f]){6})[^0-9a-fA-F]""" n=input() s="" for i in range(n): s+=raw_input() x=re.findall(reg1,s) for l in x: y=re.findall(reg2,l) #print l for z in y: print zHex Color Code solution in Python 3.# Enter your code here. Read input from STDIN. Print output to STDOUT import re N=int(input()) for i in range(0,N): s=input() x=s.split() if len(x)>1 and '{' not in x: x=re.findall(r'#[a-fA-F0-9]{3,6}',s) [print(i) for i in x]Problem solution in pypy programming.import re, sys N = int(raw_input()) for _ in range(N): line = raw_input().strip() codes = [j for j in re.findall('[s:](#[a-f0-9]{6}|#[a-f0-9]{3})[s:;,)]', line, re.I)] for code in codes: print codeProblem solution in pypy3 programming.# Enter your code here. Read input from STDIN. Print output to STDOUT import re in_block = False for x in range(int(input())): line = input() if '{' in line: in_block = True continue if '}' in line: in_block = False continue if in_block == True: m = re.findall(r'(#[a-fA-F0-9]{3,6})', line) if m: print(*m, sep='n') coding problems solutions Hackerrank Problems Solutions Python Solutions HackerRankPython