Write a program to Split tuple into groups of n and print it


Topic: Write a program to Split tuple into groups of n and print it

Solution

ini_tuple = (1, 2, 3, 4, 8, 12, 3, 34, 
             67, 45, 1, 1, 43, 65, 9, 10)
n=4
N=0
s=tuple()
for i in range(0,len(ini_tuple)//n):
    t=tuple()
    for j in range(N,N+n):
        #print(ini_tuple[j])
        t+=(ini_tuple[j],)
        
    N=N+n
    s+=(t,)    
print(s)



List all Python Programs