Last active
January 30, 2022 12:18
-
-
Save ZakriaJanjua/f371e09405cd29c3574a428fa978168a to your computer and use it in GitHub Desktop.
Coding Games MIME Type challenge. 100% solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import math | |
# Auto-generated code below aims at helping you parse | |
# the standard input according to the problem statement. | |
n = int(input()) # Number of elements which make up the association table. | |
q = int(input()) # Number Q of file names to be analyzed. | |
emlist = {} | |
for i in range(n): | |
# ext: file extension | |
# mt: MIME type. | |
ext, mt = input().split() | |
emlist[ext.lower()] = mt | |
for i in range(q): | |
fname = input() # One file name per line. | |
if not '.' in fname: | |
print('UNKNOWN') | |
continue | |
try: | |
name = fname.split('.')[-1].lower() | |
except IndexError: | |
pass | |
try: | |
value = emlist.get(name, 'UNKNOWN') | |
print(value) | |
except KeyError: | |
print('UNKNOWN') | |
except NameError: | |
continue | |
# Write an answer using print | |
# To debug: print("Debug messages...", file=sys.stderr, flush=True) | |
# For each of the Q filenames, display on a line the corresponding MIME type. If there is no corresponding type, then display UNKNOWN. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment