-3

I was trying to write script using python. i need to avoid repetition of the same tasks and want to write in one.

catlist1 = ['s0.05-k5-a1.0' , 's0.05-k5-a3.0' , 's0.05-k5-a7.0' , 's0.05-k5-a10.0' ]
catlist2 = ['s0.05-k7-a1.0' , 's0.05-k7-a3.0' , 's0.05-k7-a7.0' , 's0.05-k7-a10.0']

catlist3 = ['s0.07-k5-a1.0' , 's0.07-k5-a3.0' , 's0.07-k5-a7.0' , 's0.07-k5-a10.0' ]
catlist4 = ['s0.07-k7-a1.0' , 's0.07-k7-a3.0' , 's0.07-k7-a7.0' , 's0.07-k7-a10.0']

catlist = [catlist1 ,catlist2 ,catlist3 ,catlist4 ]

i need to call each list inside the for loop. i call all lists inside this single loop. I can do it repititvily by writing multiple times for i in catlist1 and again in catlist2 .. how could i solve this. thanks

for parName in catlist:         

    category = '/home/x/Desktop/rouge/ROUGE/Experiments/' 

    for root, subFolders, files in os.walk(category + parName):
        #i = 0 
        (head, filename) = os.path.split(root)
        print filename
        #some function that is will re
MattDMo
  • 100,794
  • 21
  • 241
  • 231
  • I fixed the duplicate link so that it points at the canonical; but I have **absolutely no idea** how multiple different people read this question and all came to the same conclusion that the problem is to flatten a list of lists into a single list. When I try to read the question, I can't make **any sense out of it at all**. – Karl Knechtel Sep 06 '22 at 02:39

2 Answers2

5
for parName in itertools.chain.from_iterable(catlist):
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
2

What you want to do is called, flattening a nested list. You can do it like this

for parName in (item for items in catlist for item in items):
thefourtheye
  • 233,700
  • 52
  • 457
  • 497