We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I have learn that in this case of situation, with "exactly 3 or 6" we can do {3}|{6}.
Instead, we have to write twice the instruction, with firstly {6} (the biggest number), then {3} (the lowest number)
Then, findall() occurences which respect this pattern (with # at the start obviously) and extend an output list to write every results at the end.
Here the code :
# Enter your code here. Read input from STDIN. Print output to STDOUTimportrepattern=r"#([0-9A-Fa-f]{6}|[0-9A-Fa-f]{3})"N=int(input())output=list()for_inrange(N):current_line=input()if":"incurrent_line:m=re.findall(pattern,current_line)ifm:output.extend(m)forelementinoutput:print(f"#{element}")
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Hex Color Code
You are viewing a single comment's thread. Return to all comments →
I have learn that in this case of situation, with "exactly 3 or 6" we can do {3}|{6}.
Instead, we have to write twice the instruction, with firstly {6} (the biggest number), then {3} (the lowest number)
Then, findall() occurences which respect this pattern (with # at the start obviously) and extend an output list to write every results at the end.
Here the code :