# lambda 函数所引起的闭包问题

s = 'ab;cd|efg|hi,jkl|mn\opq;rst,uvw/xyz'
sign = ';|\/,'

def my_split(s, sign):
s = [s]
for i in sign:
t = []
for x in s:
map(lambda x: t.extend(x.split(i)), s)
s = t
return s
print(my_split(s,sign))

def my_split(s, sign):
for i in sign:
t = []
if type(s) is list:
for j in s:
t.extend(j.split(i))
else:
s = s.split(i)
t.extend(s)
s = t
return s
print(my_split(s,sign))

['ab', 'cd', 'efg', 'hi', 'jkl', 'mn', 'opq', 'rst', 'uvw', 'xyz']

def my_split(s, sign):
s = [s]
for i in sign:
t = []
for x in s:
#map(lambda x: t.extend(x.split(i)), s)
def lambd(i, t, x, s):
map(t.extend(x.split(i)),s)
lambd(i, t, x, s) # 注意这行，这里执行了lambd函数
s = t
return s
print(my_split(s,sign))

def my_split(s, sign):
s = [s]
for i in sign:
t = []
#map(lambda x: t.extend(x.split(i)), s)
for x in s:
def lambd(i, t, x, s):
map(t.extend(x.split(i)),s)
#lambd(i, t, x, s) # 注释掉
s = t
print(s) # 打印出来
return s
print(my_split(s,sign))

http://www.cnblogs.com/Andy963/p/7043718.html

05-31 1087
05-27 3万+

09-03 6725
03-11 3584
09-11
08-06 6415
08-01 11万+
03-11 2271
03-14 7361
07-25 5015
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客