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.
Detect HTML Attributes
Detect HTML Attributes
Sort by
recency
|
105 Discussions
|
Please Login in order to post a comment
The exact code will be: import re
Read input
N = int(raw_input()) html = '' for _ in range(N): html += raw_input()
Extract tags and attributes using regex
tags = {} pattern = r'<(\w+)([^>]*)>' matches = re.findall(pattern, html)
for match in matches: tag, attrs = match if tag not in tags: tags[tag] = set()
Print output
for tag in sorted(tags): if tag == 'a': attrs = ','.join(sorted([attr for attr in tags[tag] if attr in ['accesskey', 'href', 'title']])) else: attrs = ','.join(sorted(tags[tag]))
Java 15
TreeMap holds tag and corresponding attributes as list
Regex for tag :
Regex for attribute :
Python 3
Testcase fails.
Copy testcase STDIN to custom input case box.
TEST SUCCESSFUL.
WHAT GIVES!!!
Not the prettiest code, but it definitely worked: