Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

HackerRank Hex Color Code solution in python

YASH PAL, 31 July 2024

In this Hex Color Code problem, 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.

HackerRank Hex Color Code solution in python

Problem solution in Python 2 programming.

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 z

Problem solution in Python 3 programming.

# 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 code

Problem 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 Python Solutions

Post navigation

Previous post
Next post
  • Automating Image Format Conversion with Python: A Complete Guide
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
How to download udemy paid courses for free

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
©2025 Programming101 | WordPress Theme by SuperbThemes