笔记:使用numpy 字典按字母排序

# 字典忽略大小写排序,ignore忽略大小写

def sort(dic, ignore=1):

    if type(dic) !=dict:

        return

    keys =list(dic.keys())

    if ignore:

        keys =sorted(keys, key=str.lower)

    else:

        keys.sort()

    result = {}

    for each in keys:

        if type(dic[each]) ==dict:

            result[each] = sort(dic[each], ignore)

    else:

        result[each] = dic[each]

return result

你可能感兴趣的:(笔记:使用numpy 字典按字母排序)