I have a nested tuple t1 = ((1, 'Kamil'), (2, 'Hassaan'))
and I want to copy the elements of the tuple into a list like this: [[1, 2], [Kamil, Hassaan]]
. Take 1 and 2
and combine them. Take Kamil and Hassaan
and combine them. Combine them together in a small list(temp
) and append temp in the List
.
This is my code:
t1 = ((1, 'Kamil'),
(2, 'Hassaan'))
t2 = ((1, 'python', 'print'),
(2, 'c++', 'cout'))
iSize = len(t1[0])
#print(len(t1))
index = 0
List = []
temp = []
r = 0
c = 0
while r < len(t1[0]):
while c < len(t1):
temp.append(t1[c][r])
c += 1
List.append(temp)
print(List)
c = 0
temp.clear()
print(temp)
r += 1
print(List)
You will see some unnecessary print commands. I used them to check my code. I can't understand why after one iteration the items of the List
get overwritten and then the whole List
is empty at the end.