字典映射

def ctype(old_type):
    type_map = {
             "ab1": "AB1112",
                "cd2": "CD12321",
                "ef3": "EF"
                }
    return type_map[old_type]


l = {"ab":"ab1","cd":"cd2","ef":"ef3"}
if __name__=='__main__':
    print l["ab"]
    print ctype(l["ab"])
    print ctype(l["cd"])

输出:

ab1
AB1112
CD12321

猜你喜欢

转载自blog.csdn.net/jackliu16/article/details/81074137