I am trying to element wise operation on 2 list. But in this case the list are of 2 different sizes. For example we have 2 lists. List 1 contains users and list 2 contains posts. In 1st use case if user list in longer then post, then each user first finish the post of the same index and then the list should start again.
user = [1,2,3,4,5]
posts = ['p1','p2']
posting = ['1 p1','2 p2','3 p1','4 p2','5p1'] so on so forth.
I tried something like this
def send_post(u, t):
print("execute ---------->", u, t)
return "done"
def send_t(ulist, tlist):
print("################## equal processing done")
remaining_accounts = ulist[len(tlist) - len(ulist):]
ulist_counter = len(remaining_accounts)
tlist_counter = len(tlist)
for j in range(len(remaining_accounts)):
if tlist_counter == 0:
send_t(remaining_accounts, tlist)
send_post(remaining_accounts[j], tlist[j])
ulist_counter -= 1
tlist_counter -= 1
if ulist_counter ==0:
break
#
#
#
ulist = ['u1', 'u2', 'u3', "u4", "u5"]
tlist = ['t1', 't2']
send_t(ulist,tlist)
I am new to recursion and python. please help. I am getting this error.
execute ----------> u3 t1
execute ----------> u4 t2
################## equal processing done
execute ----------> u5 t1
Traceback (most recent call last):
File ".\tests.py", line 72, in <module>
send_t(ulist,tlist)
File ".\tests.py", line 59, in send_t
send_post(remaining_accounts[j], tlist[j])
IndexError: list index out of range