Last active
October 28, 2017 11:31
-
-
Save hbd/7d671c3a068be7fcf48b47f658344613 to your computer and use it in GitHub Desktop.
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
# taken from discussion -- not original code | |
n = int(input().strip()) | |
bucket = defaultdict(list) # bucket, actually a list with 1 key/n values | |
# store each input in the appropriate sub-bucket location | |
# use the string's length as the index (key), and appends it at that sub-bucket location | |
# this collects all string of the same length in the same sub-bucket location | |
for _ in range(n): | |
number = input().strip() | |
bucket[len(number)].append(number) | |
# the bucket is then sorted in terms of length, and the items within each sub-bucket are | |
# then sorted alphabetically (thanks to python) | |
for key in sorted(bucket): | |
for value in sorted(bucket[key]): # each value in the sub-bucket is sorted alphabetically (thanks python!) | |
print(value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment