有没有更快的方法来拆分列表中的元素并包括拆分元素.如果元素是单词,则不需要再次添加拆分元素.我目前的工作解决方案如下所示,如果有任何改进的话,我只想要改进
final_list = []
lists = ["the", "I am there", "call me"]
for l in lists:
splitted_l = l.split()
if len(splitted_l) == 1:
final_list.append(splitted_l)
else:
splitted_l.append(l)
final_list.append(splitted_l)
print(final_list)
---------
output = [['the'], ['I', 'am', 'there', 'I am there'], ['call', 'me', 'call me']]