我需要将下面的数组分成三个数组: tc_excel变量的结果
[(1000000, ['FA'], 'bev.xml'),
(1001001, ['TC', 'CT03', 'CT04'], False),
(1003000, ['FA'], 'phev.xml'),
(1003001, ['TC', 'CT01', 'CT03', 'CT04'], False),
(1003002, ['TC', 'CT01', 'CT03', 'CT04'], False),
(1004000, ['FA'], 'tesla.xml'),
(1004001, ['TC', 'CT03', 'CT04'], False),
(1004002, ['TC', 'CT03', 'CT04'], False)]
所有拆分后的数组应至少有一个['FA']其中的第一个,(
['1000000,'1003000,'1004000]
def testcasefilter(tc_input, tc_max, config_reiter, excel_pfad):
if abs(tc_max) < 2:
return []
if not os.path.isfile(excel_pfad):
return []
tc_excel = get_fnt_testcases(excel_pfad, config_reiter)
intervalls, kats, notkats = decode_tc_selection(tc_input)
print tc_excel
tc_excel_ok = []
tc_codierung_ok = []
for id_, katlist, cod in tc_excel:
for kat in katlist:
if kat in kats:
tc_excel_ok.append(id_)
if cod:
tc_codierung_ok.append(id_)
break
elif notkats and kat not in notkats:
tc_excel_ok.append(id_)
if cod:
tc_codierung_ok.append(id_)
break
else:
if notkats and not katlist:
tc_excel_ok.append(id_)
if cod:
tc_codierung_ok.append(id_)
elif check_tc_spec(id_, intervalls):
tc_excel_ok.append(id_)
if cod:
tc_codierung_ok.append(id_)
temp_out = []
cod = None
temp = []
if tc_max < 0:
tc_max = len(tc_excel_ok) / abs(tc_max) + 2 # +1 Extra-Kodiertestcase +1 Rundung
if tc_max < 2:
return []
for tc in tc_excel_ok:
if len(temp) < tc_max:
temp.append(tc)
if tc in tc_codierung_ok:
cod = tc
else:
temp_out.append(temp)
temp = [tc]
if tc in tc_codierung_ok:
cod = tc
elif cod is not None:
temp = [cod, tc]
temp_out.append(temp)
output = []
for elem in temp_out:
o = ""
for e in elem:
o += str(e) + ";"
output.append(o[:-1])
return output
if __name__ == "__main__":
print testcasefilter("*", 3, "Konfiguration", r"C:\Data\DSPLIT.xlsx")
结果输出应该像是因为我们有一个pev一个phev,而第三个xml不是bev或不是phev ['1000000; 1001001','1003000; 1003001; 1003002','1004000; 1004001; 1004002']
答案 0 :(得分:1)
这是解决方案:
test = [(1000000, ['FA'], 'bev.xml'),
(1001001, ['TC', 'CT03', 'CT04'], False),
(1003000, ['FA'], 'phev.xml'),
(1003001, ['TC', 'CT01', 'CT03', 'CT04'], False),
(1003002, ['TC', 'CT01', 'CT03', 'CT04'], False),
(1004000, ['FA'], 'tesla.xml'),
(1004001, ['TC', 'CT03', 'CT04'], False),
(1004002, ['TC', 'CT03', 'CT04'], False)]
bev = [1003000]
notbev = [1000000,100400]
arrayall = [1000000,1001001,1003000,1003001,1003002,1004000,1004001,1004002]
arr_part_bev = []
arr_part_not_bev = []
isbev = False
for i in arrayall:
if i in bev:
arr_part_bev.append(i)
isbev = True
elif i in notbev:
arr_part_not_bev.append(i)
isbev = False
else:
if isbev:
arr_part_bev.append(i)
else :
arr_part_not_bev.append(i)
print (arr_part_bev)
print (arr_part_not_bev)