Python 我在这两种情况下都会被引用,但当我以不同的方式编写时,它会给我一个错误

Python 我在这两种情况下都会被引用,但当我以不同的方式编写时,它会给我一个错误,python,Python,给我一个错误 def censor(line): return ''.join(i ='*' * len(i) if len(i) > 4 else i for i in line) 但当我说I='*'*leni尝试: def censor2 (your_word): spl = your_word.split() empty_list = [] for i in spl: if len(i) >= 4: i = '*' * len(i) empty

给我一个错误

def censor(line):
return ''.join(i ='*' * len(i) if len(i) > 4 else i for i in line)
但当我说I='*'*leni

尝试:

def censor2 (your_word):
spl = your_word.split()
empty_list = []
for i in spl:
    if len(i) >= 4:
        i = '*' * len(i)
    empty_list.append(i)
return ' '.join(empty_list)

如果此处也不需要条件,则不允许在快捷方式中使用作业,如i=。

谢谢您的帮助
def censor(line):
    return ''.join('*' * len(i) if len(i) > 4 else i for i in line)