哈工大python期末考试编程1

def get_standard_str(s):
    lis = list(s)
    lis.sort()
    s = "".join(lis)
    return s


stop_word = ""
dict1 = {}

for line in iter(input, stop_word):
    standard_str = get_standard_str(line)
    if standard_str in dict1:
        dict1[standard_str].append(line)
    else:
        dict1[standard_str] = [line]

len_list = []
dict2 = {}

for(k, v) in dict1.items():
    one_len = len(v)
    if one_len not in len_list:
        len_list.append(one_len)
    if one_len in dict2:
        dict2[one_len].append(v[0])
    else:
        dict2[one_len] = [v[0]]


len_list.sort(reverse=True)
for word_num in len_list:
    for keys in dict2[word_num]:
        new_keys = get_standard_str(keys)
        print(' '.join(dict1[new_keys]))

你可能感兴趣的:(哈工大python)