Discuss / Python / 2023-6-10 17:52:52

2023-6-10 17:52:52

Topic source

def normalize(name):

    a=name[0].upper()+name[1:].lower()

    return a

我又简化了下本章中的例题【dog】

from functools import reduce

DIGITS ={f'{k}':k for k in range(10)}

def char2num(s):

    return DIGITS[s]

def str2int(s):

    return reduce(lambda x, y: x * 10 + y, map(char2num, s))

print(char2num("5"))

print(str2int("5645213256479"))


  • 1

Reply