Return to JUNTO

JUNTO Practice: Hackerrank, "Detect the Domain Name"

Discussed on May 22, 2019.

Hackerrank, "Detect the Domain Name"

Solutions

Click to see:

Oscar Martinez

import re
import sys

domain_re = re.compile(
    r"https?://(?:www2?\.)?([a-z0-9\-]+(?:\.[a-z0-9\-]+)+)/?"
)

domains = set(
    domain_re.findall(
        sys.stdin.read().replace(
            "\n", " "
        )
    )
)

sys.stdout.write(
    ";".join(sorted(domains))
)

John Lekberg

import sys
import re

domain_re = re.compile(
    r"""
    https?://
    (?:(?:www|ww2)\.)?
    ([a-zA-Z0-9-]+ (?: \. [a-zA-Z0-9-]+)+)
    """,
    re.VERBOSE,
)

candidates = set(
    domain_re.findall(sys.stdin.read())
)

print(";".join(sorted(candidates)))

Daniel Bassett

import re
import sys

unique_re = re.compile(
    r"https?://(?:ww[w2]\.)?([a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)+)/?"
)

uniquedomains = set(
    unique_re.findall(sys.stdin.read())
)
print(";".join(sorted(uniquedomains)))