I have a list of 9 lists, inside every lists there are few elements. Every elements are string. Now I want to create another list of lists based upon partially similar string. I can do that individually, without using conditional statement. But I want to do it using if condition.
What I have tried :
var = ["pr", "tas", "ts"]
prs = []
for i in all_files:
for j in i:
if var[0] in j:
prs.append(j)
tass = []
for i in all_files:
for j in i:
if var[1] in j:
tass.append(j)
tss = []
for i in all_files:
for j in i:
if var[2] in j:
tss.append(j)
In the above way I can do that thing. But I want to loop over var as well. For that I have tried :
gg = []
for i in all_files:
for j in i:
for k in var[0:3]:
kk = []
if k in j:
kk.append(j)
gg.append(kk)
It is giving a list, but there are so many blank lists inside that list. I want all the "pr" containing file would be in a list, same for "ts" and "tas" and they will be inside a list. Please let me know if anyone have any doubt Thank you.