最好的分割方式是什么:
tuple = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h')
进入这个:
tuples = [('a', 'b'), ('c', 'd'), ('e', 'f'), ('g', 'h')]
假设输入总是有偶数个值。
最佳答案
zip()
是你的 friend :
t = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h')
zip(t[::2], t[1::2])
关于python - Python 中的多元组到两对元组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/756550/