Discuss / Python / 交一交作业

交一交作业

Topic source

test_number

#1 Created at ... [Delete] [Delete and Lock User]

第一题: def normalize(name): name=name[0].upper()+name[1:].lower() return name

r=list(map(normalize,['adam', 'LISA', 'barT']))

print r

第二题: from functools import reduce def prod(L): return reduce(lambda x, y: x*y, L) print(prod([3, 5, 7, 9]))

第三天: from functools import reduce

DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}

def char2num(s): return DIGITS[s]

def str2float(s): return reduce(lambda x, y: x 10 + y, map(char2num, s.split('.')[0])) + reduce(lambda x, y: x 0.1 + y, map(char2num, s.split('.')[1][::-1]))*0.1

s='123.456' print s

test_number

#2 Created at ... [Delete] [Delete and Lock User]

第三题: from functools import reduce

DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}

def char2num(s): return DIGITS[s]

def str2float(s): return reduce(lambda x, y: x10 + y, map(char2num, s.split('.')[0])) + reduce(lambda x, y: x0.1 + y, map(char2num, s.split('.')[1][::-1]))*0.1

s='123.456' print s


  • 1

Reply