I have this list. I want to make a for
loop that will use in a function combinations of these files in the list.
I am not sure how to make these combinations that for each 'check' it will take the correct combination.
The function if it wasn't for the loop it would look like this:
erase('check3_dwg_Polyline','check3_dwg_Polyline_feat_to_polyg_feat_to_line','output_name')
What I've tried:
Here's the list.
li=['check3_dwg_Polyline', 'check2_dwg_Polyline',
'check3_dwg_Polyline_feat_to_polyg',# this will not be needed to extracted
'check2_dwg_Polyline_feat_to_polyg',# >> >>
'check3_dwg_Polyline_feat_to_polyg_feat_to_line',
'check2_dwg_Polyline_feat_to_polyg_feat_to_line']
start with this:
a=[li[i:i+3] for i in range(0, len(li), 3)]
where returns:
[['check3_dwg_Polyline',
'check2_dwg_Polyline',
'check3_dwg_Polyline_feat_to_polyg'],
['check2_dwg_Polyline_feat_to_polyg',
'check3_dwg_Polyline_feat_to_polyg_feat_to_line',
'check2_dwg_Polyline_feat_to_polyg_feat_to_line']]
Finally:
for base, base_f, base_line in a:
print(base, base_line, base + "_output")
gives:
check3_dwg_Polyline check3_dwg_Polyline_feat_to_polyg check3_dwg_Polyline_output
check2_dwg_Polyline_feat_to_polyg check2_dwg_Polyline_feat_to_polyg_feat_to_line check2_dwg_Polyline_feat_to_polyg_output
Other method:
base = [f for f in li if not f.endswith(("_polyg", "_to_line"))]
base_f = {f.strip("_feat_to_polyg"): f for f in li if f.endswith("_polyg")}
base_line = {f.strip("_feat_to_polyg_feat_to_line"): f for f in li if f.endswith("_to_line")}
[(b, base_f[b], base_line[b]) for b in base]
gives:
KeyError: 'check3_dwg_Polyline'
I have tried sorting the list but it just ruins it in a different way when put through the processes mentioned above.
The ideal result is this
when trying this:
for base, base_f, base_line in a:
print(base, base_line, base + "_output")
to give this:
check3_dwg_Polyline check3_dwg_Polyline_feat_to_polyg_feat_to_line check3_dwg_Polyline_output
check2_dwg_Polyline check2_dwg_Polyline_feat_to_polyg_feat_to_line check2_dwg_Polyline_output
where will be put in like this:
erase('check3_dwg_Polyline','check3_dwg_Polyline_feat_to_polyg_feat_to_line','output_name')