打印每个输出一次: f1=['part3_pl', 'part2_pl', 'part3_pl_to_p', 'part2_pl_to_p', 'part3_pl_to_p_lack', 'part2_pl_to_p_lack']for i in f1: for j in f1: if i.endswith('pl') and j.endswith('pl_to_p'): print(i,j,i+'_output')返回值:part3_pl part3_pl_to_p part3_pl_outputpart3_pl part2_pl_to_p part3_pl_outputpart2_pl part3_pl_to_p part2_pl_outputpart2_pl part2_pl_to_p part2_pl_output我想每行打印一次。正确的输出:part3_pl part3_pl_to_p part3_pl_outputpart2_pl part2_pl_to_p part2_pl_output
1 回答
慕虎7371278
TA贡献1802条经验 获得超4个赞
请再次检查输出。根据您的代码,输出应为:
for i in f1:
for j in f1:
if i.endswith('pl') and j.endswith('pl_to_p'):
print(i,j,i+'_output')
输出 :
part3_pl part3_pl_to_p part3_pl_output
part3_pl part2_pl_to_p part3_pl_output
part2_pl part3_pl_to_p part2_pl_output
part2_pl part2_pl_to_p part2_pl_output
所需的输出可以通过以下代码实现:
for i in f1:
for j in f1:
if i.endswith('pl') and j==i+ '_to_p':
print(i,j,i+'_output')
添加回答
举报
0/150
提交
取消