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.
Hi,
my solution is very similar to yours. It just uses OrderedDict, which keeps the order of the pairs, when you print them.
fromcollectionsimportOrderedDict#define empty ordered dictionary, which counts occurencesdict=OrderedDict()foriinrange(int(input())):#If input not in the dictionary, then add it#else increment the counterkey=input()ifnotkeyindict.keys():dict.update({key:1})continuedict[key]+=1print(len(dict.keys()))print(*dict.values())
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Word Order
You are viewing a single comment's thread. Return to all comments →
Hi, my solution is very similar to yours. It just uses OrderedDict, which keeps the order of the pairs, when you print them.