Discuss / Python / 交作业--MapReduce

### 交作业--MapReduce

Topic source

#### 安迪博德

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

L1 = ['adam', 'LISA', 'barT'] L2 = list(map(normalize, L1)) print(L2)

print('3 5 7 * 9 =', prod([3, 5, 7, 9]))

def fn(x, y): return x 10 + y def cvt(s): return {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9}[s] def str2float(s): if ('.' in s): idx = s.index('.') s1 = s[:idx] s2 = s[idx+1:] return str2float(s1) + str2float(s2)/(10*idx) else: return reduce(fn,map(cvt,s))

print('str2float(\'123.456\') =', str2float('123.456'))

#### 安迪博德

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

from functools import reduce

def fn(x, y): return x*10 + y def cvt(s): return {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9}[s]

def str2float(s): if ('.' in s): idx = s.index('.') s1 = s[:idx] s2 = s[idx+1:] return str2float(s1) + str2float(s2)/(10**idx) else: return reduce(fn,map(cvt,s))

print('str2float(\'123.456\') =', str2float('123.456'))

#### 酷酷哒小强24

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

• 1