python 3.5 中的 zip 函数具有超过 255 个参数
zip function in python 3.5 with more than 255 arguments
我在代码中有一个 zip 函数给我错误 "SyntaxError: more than 255 arguments"
sentences_join = [' '.join(x) for x in zip(sentences[0::256], sentences[1::256], sentences[2::256], sentences[3::256], ..., sentences[255::256])]
如何将此函数压缩为少于 255 个参数?
apply
函数的 Python 方式可以将可迭代对象转换为参数:
sentences_join = [' '.join(x) for x in zip(*map(lambda i: sentences[i::256], range(256)))]
尝试
sentences_join = [' '.join(x) for x in zip(*(sentences[n::256] for n in range(256)))]
我在代码中有一个 zip 函数给我错误 "SyntaxError: more than 255 arguments"
sentences_join = [' '.join(x) for x in zip(sentences[0::256], sentences[1::256], sentences[2::256], sentences[3::256], ..., sentences[255::256])]
如何将此函数压缩为少于 255 个参数?
apply
函数的 Python 方式可以将可迭代对象转换为参数:
sentences_join = [' '.join(x) for x in zip(*map(lambda i: sentences[i::256], range(256)))]
尝试
sentences_join = [' '.join(x) for x in zip(*(sentences[n::256] for n in range(256)))]