我在代码中有一个zip函数,给出了错误“SyntaxError:超过255个参数”
sentences_join = [' '.join(x) for x in zip(sentences[0::256], sentences[1::256], sentences[2::256], sentences[3::256], ..., sentences[255::256])]
如何将此函数压缩为少于255个参数?
答案 0 :(得分:2)
尝试
sentences_join = [' '.join(x) for x in zip(*(sentences[n::256] for n in range(256)))]
答案 1 :(得分:1)
apply
函数的Pythonic方式可以将迭代变为参数:
sentences_join = [' '.join(x) for x in zip(*map(lambda i: sentences[i::256], range(256)))]