【发布时间】:2020-02-16 22:12:57
【问题描述】:
我正在尝试学习在 python 中做事的函数式编程方式。我正在尝试使用以下代码序列化 python 中的字符串列表
S = ["geeks", "are", "awesome"]
reduce(lambda x, y: (str(len(x)) + '~' + x) + (str(len(y)) + '~' + y), S)
我期待:
5~geeks3~are7~awesome
但我看到了:
12~5~geeks3~are7~awesome
有人能指出原因吗?提前致谢!
【问题讨论】: