python 3.5中的zip函数,包含超过255个参数

时间:2018-04-14 21:44:22

标签: python syntax-error python-3.5

我在代码中有一个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个参数?

2 个答案:

答案 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)))]