Concatenate Python lists of different lengths by ID

  list, python-3.x, string-concatenation

I have a script that finds substrings in a list, but in the last loop it does not concatenate the strings correctly.
Correct result:

IDS00388680 Block Commands
IDS00389632 empty
IDS00389629 Run queue offset
IDS00389628 empty

Script result:

['IDS00388680', 'Verification error', 'Block Commands']
['IDS00389632', 'Run queue offset', 'Team LS']
['IDS00389629', 'empty', 'empty']
['IDS00389628', 'empty', 'empty']

Error in the "Step3" loop.
I need to combine the results "data", "result_cycle" by number IDS***
Any ideas on how to fix this error?

My Script:

import re
from itertools import zip_longest

task_list = [('IDS00388680', 'https://jira.domain/browse/30682rnrnA call to the block command has been registered: IDS0147121164rnerror: [Teradata][ODBC Teradata Driver] will be decided in circulation.')
,('IDS00389632', 'https://jira.domain/browse/30752rnrnOne-time failure, probably due to the procedure freezing for a second, the problem was fixed by restarting.rn incident resolved')
,('IDS00389629', 'https://jira.domain/browse/30753rnrnThe package did not have time to finish work due to launch at the end of the day.rnReconfigured the clusterrn incident resolved')
,('IDS00389628', 'https://jira.domain/browse/30754rnrnReduced resources as a result, there were not enough threads to execute.rn incident resolved')]

t_inf = list()
tabl_inf = []
pre_result = []
pre_pre_result = []
result_cycle = []
result = []
data = []

reason = {"Run queue offset":["The package did not have time to finish work due to the end of the day"
                             ,"The package did not have time to finish work due to launch at the end of the day"],
          "Verification error": ["A call to the block command has been registered"]}
work_command = {"Block Commands":["Verification error"],
                "Team LS":["Run queue offset"
                          ,"Infrastructure"]}

tabl_inf = [1, 2, 6, 11, 5, 1, 1, 1] #substring count result  

#Step1 - search the key in the dictionary reason
for n, m in zip(task_list,tabl_inf):
    full_str = re.sub('s+',' ',n[1])
    data.append([n[0],n[1],m])
    for key, item in reason.items():
        for itm in item:
            if itm in full_str:
                reason_val = key
                pre_result.append([n[0],reason_val])

#Step2 - search the key in the dictionary work_command                
for i in pre_result:
    for key, item in work_command.items():
        for itm in item:
            if itm in i[1]:
                work_command_val = key
                pre_pre_result.append([i[0],work_command_val])

for i, ii in zip(pre_result, pre_pre_result):
    result_cycle.append([i[0],i[1],ii[1]])

#Step3 - concatenate the IDS field in the task_list and the values ​​from the result_cycle
ziplong = zip_longest(data, result_cycle, fillvalue='empty')
for i in ziplong:
    if i[1] != "empty":
        result.append([i[0][0], i[1][1], i[1][2]])
    else:
        result.append([i[0][0], "empty", "empty"])

for m in result:
    print(m)

Source: Python-3x Questions

LEAVE A COMMENT