如何在下面的示例中轉換為像我這樣的形式:例如:
[a, b, c,d] >> [(a,b) (c,d)]
[a,b,c,d]
#wish to be like this
[(a,b) (c,d)]
謝謝
uj5u.com熱心網友回復:
嘗試這個;
l = ['a','b','c','d']
n = 2
lst = []
for i in range(0, len(l), n):
lst.append(tuple(l[i:i n]))
#Output
[('a', 'b'), ('c', 'd')]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/511906.html
標籤:Python数组麻木的
