哈工大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]))

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章