假定现在有两个list:from_meta_symbols和from_text_symbols,现在需要对这两个list进行merge
1. 错误的做法:
def merge_two_list(from_meta_symbols, from_text_symbols):
return list(set(from_meta_symbols.extend(from_text_symbols)))
会导致报错:
TypeError: 'NoneType' object is not iterable
2. 正确的做法:
def merge_two_list(from_meta_symbols, from_text_symbols):
from_meta_symbols.extend(from_text_symbols)
return list(set(from_meta_symbols))
3. 主要原因:
在python语言中,list数据结果执行完extend操作后,返回的结果是NoneType。且list本身的数据结构已经发生改变了。