I have searched everywhere on how to rotate/shift each element of a list simultaneously (using different speed) but nothing is found. the solutions in the following links only shift the entire list or doesn't solve my issue:
Efficient way to rotate a list in python
https://www.geeksforgeeks.org/python-ways-to-rotate-a-list/
How to iterate all item at once in python list?
This is what am trying:
test_list = ['abcde', 'fghij', 'klmno', 'pqrst', 'uvwxy']
def idx_1():
for i in range(10):
a1 = list(test_list[0])
for i in range(len(a1)):
a1.append(a1.pop(0))
pkidx_1 = "".join(a1)
time.sleep(0) #to control/determine speed of iteration
print(pkidx_1)
def idx_2():
for i in range(10):
a2 = list(test_list[1])
for i in range(len(a2)):
a2.append(a2.pop(0))
pkidx_2 = "".join(a2)
time.sleep(0.0001)
print(pkidx_2)
def idx_3():
for i in range(10):
a3 = list(test_list[2])
for i in range(len(a3)):
a3.append(a3.pop(0))
pkidx_3 = "".join(a3)
time.sleep(0.0002)
print(pkidx_3)
def idx_4():
for i in range(10):
a4 = list(test_list[3])
for i in range(len(a4)):
a4.append(a4.pop(0))
pkidx_4 = "".join(a4)
time.sleep(0.0003)
print(pkidx_4)
def idx_5():
for i in range(10):
a5 = list(test_list[4])
for i in range(len(a5)):
a5.append(a5.pop(0))
pkidx_5 = "".join(a5)
time.sleep(0.0004)
print(pkidx_5)
if __name__=='__main__':
p1 = threading.Thread(target=idx_1)
p2 = threading.Thread(target=idx_2)
p3 = threading.Thread(target=idx_3)
p4 = threading.Thread(target=idx_4)
p5 = threading.Thread(target=idx_5)
p1.start();p2.start();p3.start();p4.start();p5.start()
But i get stucked merging all the output to emit as a single list/variable. Expected output:
['abcde', 'fghij', 'klmno', 'pqrst', 'uvwxy']
['bcdea', 'ghijf', 'lmnok', 'qrstp', 'vwxyu']
['cdeab', 'hijfg', 'mnokl', 'rstpq', 'wxyuv']
['deabc', 'ijfgh', 'noklm', 'stpqr', 'xyuvw']
['eabcd', 'jfghi', 'oklmn', 'tpqrs', 'yuvwx']
['abcde', 'fghij', 'klmno', 'pqrst', 'uvwxy']
The #time.sleep may influence the result though i.e by the time idx_5 (slowest def) finish its first iteration, the faster would have cycle more times and so on.
Thanks in advance.