I have nested functions that are meant to partition the indices of a list of lists, corresponding to elements (lists) that are the same.
My first attempt wasn't returning the list I needed from an inside function. i thought it was because the output list was created inside the function only. So I modified the script. I now define my output list, liketissuesets, exernally. It is passed to, and modified by, the internal functions. And yet, the correctly modified list is not passing from the function ind_list_renew to the function find_like_tissues_set!
#!/usr/bin/env python
import numpy as np
l1 = [1,2,3]
l2=[2,3]
l3=[1,2,3]
l4=[2,3,4]
l5=[2,3]
mylist = [l1,l2,l3,l4,l5]
liketissuesets = []
def listidentity(v,b,f):
if len(v) != len(b):
return []
else:
for j in range(len(b)):
if v[j]!=b[j]:
return []
else:
return [f]
def ind_list_renew(changinglist, liketissuesets):
a=changinglist[0]
b=mylist[a]
common = []
for f,v in enumerate(mylist):
common = common + listidentity(v,b,f)
print(common)
liketissuesets = liketissuesets + [common]
print(liketissuesets)
changinglist = changinglist.tolist()
indtodelete = [j for j,k in enumerate(changinglist) if k in common]
changinglist = np.delete(changinglist, indtodelete)
if len(changinglist) != 0:
ind_list_renew(changinglist, liketissuesets)
else:
print('yay', liketissuesets)
return liketissuesets
def find_like_tissues_set(mylist, liketissuesets):
indoriginal = np.arange(len(mylist))
c=ind_list_renew(indoriginal, liketissuesets)
print(c)
return c
b=find_like_tissues_set(mylist, liketissuesets)
print(b)
return ind_list_renew(changinglist, liketissuesets).