首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有条件地将大数组分解成小部分

有条件地将大数组分解成小部分
EN

Stack Overflow用户
提问于 2020-10-12 19:10:19
回答 1查看 54关注 0票数 0

我需要将下面的数组分成三个数组: tc_excel变量的结果

代码语言:javascript
复制
[(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)]

  • One数组应该是所有带有
  • 的带有"bev“的测试用例,第二个数组的名称应该是xml文件
  • ,其余的都应该是

所有分裂的数组都应该有一个最小的'FA‘号,( ['1000000,'1003000,'1004000] )

代码语言:javascript
复制
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;100400’

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-18 20:24:50

以下是解决办法:

代码语言:javascript
复制
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)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64323983

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档