-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
  • 96,286
  • 20
  • 232
  • 224

2 Answers2

5
for parName in itertools.chain.from_iterable(catlist):
Ignacio Vazquez-Abrams
  • 740,318
  • 145
  • 1,296
  • 1,325
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
  • 221,210
  • 51
  • 432
  • 478