Find the same value between two complex lists and create the combination in python

Question:

I have two complex lists route_white_list and consumer_white_list like the bellow:

route_white_list = [('pcs-disbursement-rec', {'acl': ['no']}), ('atl-card', {'acl': ['pcidss-customer']}), ('bnpl-payment', {'acl': ['bnpl']}), ('lcs-dms1', {'acl': ['no']}), ('eappendix-file', {'acl': ['no']}), ('local-cs', {'acl': ['no']}), ('notification-hub-general', {'acl': ['notification']}), ('jenkins-bnpl', {'acl': ['no']}), ('eappdendix', {'acl': ['no']}), ('ids-customer', {'acl': ['customer']}), ('atl-el', {'acl': ['atl-el']}), ('esign2-web', {'acl': ['no']}), ('customer', {'acl': ['customer']}), ('ola', {'acl': ['ola']}), ('smt-preprod', {'acl': ['no']}), ('location-pos-api', {'acl': ['no']}), ('hosel-cs', {'acl': ['no']}), ('bot', {'acl': ['bot']}), ('econtract3-file', {'acl': ['no']}), ('identity', {'acl': ['identity']}), ('bnpl-helper', {'acl': ['no']}), (None, {'acl': ['no']}), ('transaction-service-v2', {'acl': ['bnpl']}), ('web-api', {'acl': ['no']}), ('smt-uat', {'acl': ['no']}), ('voicebot', {'acl': ['voicebot']}), ('bnpl-documents', {'acl': ['no']}), ('smt-notify', {'acl': ['no']}), ('users', {'acl': ['users']}), (None, {'acl': ['no']}), ('financing', {'acl': ['financing']}), ('arm-api', {'acl': ['ola']}), ('esupplement-file', {'acl': ['no']}), ('master-data', {'acl': ['no']}), ('lucky-draw-download', {'acl': ['no']}), ('lead-epos2', {'acl': ['financing']}), ('cic-checking', {'acl': ['cic-checking']}), ('mock-server', {'acl': ['no']}), ('esigning', {'acl': ['customer']}), ('lcs-uat', {'acl': ['no']}), ('bnpl-web-be', {'acl': ['no']}), ('smt-sms', {'acl': ['no']}), ('ids-esigning', {'acl': ['no']}), ('atl-common-update-donot-call-list', {'acl': ['common-ais']}), ('arm', {'acl': ['arm']}), ('mobile-basic-auth-api', {'acl': ['no']}), ('cas-qc', {'acl': ['cas-qc']}), ('client', {'acl': ['client']}), ('arm_ui', {'acl': ['no']}), ('financialPartner', {'acl': ['financialPartner']}), ('ekyc', {'acl': ['ekyc']}), ('econsent-service', {'acl': ['no']}), ('partner-user', {'acl': ['no']}), ('smt-dev', {'acl': ['smt']}), ('cic-checking-ext', {'acl': ['no']}), ('ssmt-stag', {'acl': ['no']}), ('bnpl-payment-service', {'acl': ['bnpl']}), ('tokenization-provider', {'acl': ['tokenization-provider']}), ('smt-stag', {'acl': ['smt']}), ('ssmt', {'acl': ['no']}), ('bnpl-helper-kong-plugins-checker', {'acl': ['no']}), ('pcs', {'acl': ['no']}), ('smt-mail', {'acl': ['no']}), ('cas-dev', {'acl': ['cas-dev']}), ('ola1', {'acl': ['ola']}), ('dms-api-ext', {'acl': ['no']}), ('vbcls', {'acl': ['vbcls']}), ('atl-card-customer', {'acl': ['pcidss-customer']}), ('dms', {'acl': ['dms']}), ('atl-bnpl', {'acl': ['bnpl']}), ('msa', {'acl': ['msa']}), ('atl-common-callTask', {'acl': ['atl-common-callTask']}), ('mobile-auth-api', {'acl': ['no']}), ('smt-uat-api', {'acl': ['no']}), ('user-services', {'acl': ['user-services']}), ('tuvv', {'acl': ['tuvv']}), ('pcms-ext', {'acl': ['no']}), ('lcs', {'acl': ['no']}), ('payment-overpayment', {'acl': ['no']}), ('local-cs-security', {'acl': ['no']}), ('partnerAuthenticationV2', {'acl': ['no']}), ('esign2-file', {'acl': ['no']}), ('aps', {'acl': ['aps', 'dms']}), ('lead', {'acl': ['lead']}), ('devportal_open', {'acl': ['no']}), ('arm1', {'acl': ['ola']}), ('cev-api-route', {'acl': ['no']}), ('esigning-check-appendix', {'acl': ['esign-homex']}), ('transaction-service', {'acl': ['bnpl']}), ('mobile-documents-api', {'acl': ['no']}), ('documents', {'acl': ['no']}), ('tuvv1', {'acl': ['tuvv']}), ('atl-bnpl-account-view', {'acl': ['no']}), ('lucky-draw', {'acl': ['lucky-draw']}), ('account-service', {'acl': ['bnpl-account-service']}), ('smt_reply', {'acl': ['no']}), ('ola-qc', {'acl': ['ola']}), ('internalHelper', {'acl': ['no']}), ('econsent3-file', {'acl': ['no']}), ('esigning-sale-api', {'acl': ['no']})]

consumer_white_list = [('icmsUser', ['arm', 'icms']), ('ssmtUser', []), ('HCVN', ['devportal_common', 'devportal_admin']), ('salesUser', []), ('internalPartner', ['customer']), ('vnpay_user', ['financing', 'financialPartner']), ('dmsUser', ['dms', 'arm']), ('viettelpay_user', ['financing', 'financialPartner']), ('tm_xnk_viettel', ['financing']), ('tuConsumer', ['customer', 'testACLGroup']), ('msaUser', ['msa', 'arm']), ('sao_bnpl', ['bnpl']), ('mobileApp', ['identity', 'client']), ('fptUser', ['financing', 'bot']), ('cicCheckingUser', ['arm', 'cic-checking']), ('armUser', ['arm']), ('nguyenkim_user', ['financing']), ('airpay_user', ['financialPartner']), ('lcsUser', []), ('cusApp', ['pcs']), ('oapi_capp_clx', ['financing']), ('smtReplyMessage', ['smt_reply']), ('lam-consumer', ['lam-test-1']), ('smtUser', ['arm', 'smt']), ('bnpl-tiki', ['bnpl']), ('developer_1000300', ['customer']), ('oapi_capp_acl', ['financing']), ('gma', ['financing', 'ekyc', 'pcs']), ('vbclsUser', ['arm', 'vbcls']), ('oapiUser', []), ('infobip', ['financing']), ('momo_user', ['financialPartner', 'financing', 'atl-common-callTask']), ('jenkins-bnpl', []), ('oapi_lp_acl', ['financing', 'customer', 'client']), ('sc', ['atl-el']), ('mPosUser', ['financing', 'customer']), ('oapi_lp_online', ['financing', 'user-services', 'identity', 'customer', 'pcidss-customer', 'client', 'customerpartner', 'users']), ('dongpt1_1000109', ['financing']), ('luckyDrawUser', ['arm', 'lucky-draw']), ('webapp', []), ('ivrssUser', ['arm', 'ivrss']), ('bnpl-integration', ['notification']), ('fpt_voicebot', ['voicebot', 'financing']), ('homexUser', ['esign-homex', 'ekyc']), ('pcmsUser', ['pcms', 'arm']), ('financialPartner', ['financialPartner']), ('bnpl-mpos', ['bnpl']), ('developer_1000110', ['customer']), ('CCT', ['users', 'client']), ('ivrUserDev', ['lcs']), ('minhNguyet', ['financing']), ('khangbui2_1000107', ['financing']), ('epos2User', ['ekyc']), ('baokimUser', ['pcs', 'financialPartner']), ('OpenAPI_Test', ['financing', 'customer', 'users', 'financialPartner', 'pcs', 'identity', 'client']), ('bnpl-onepay', ['bnpl']), ('pcsUser', ['dms', 'tuvv', 'pcs']), ('dmsApiExtUser', []), ('gapUser', ['pcs']), ('casAdminUser', ['cas-qc', 'arm', 'cas', 'cas-dev']), ('tipperUser', []), ('aisUser', ['local-cs']), ('bnpl-web', ['bnpl-account-service', 'tokenization-provider']), ('cuong-test', []), ('paymentUser', ['arm', 'payment']), ('olaUser', ['ola', 'arm']), ('ivr_voicebot', ['voicebot']), ('zalopay_user', ['financialPartner', 'financing']), ('security_bnpl', ['bnpl']), ('WebScore', ['identity', 'customer']), ('superUser', ['client', 'users', 'pcs', 'identity', 'financialPartner', 'pcidss', 'master-data', 'pcidss-customer', 'customerpartner', 'ekyc', 'customer', 'financing']), ('developer_1000802', ['customer']), ('lcs-dms', ['lcs-dms']), ('cuong.test1_1000102', ['financing']), ('caophongPartner', ['financing']), ('pcs-user', []), ('oapi_mw_aldi', ['financing']), ('tvh', ['financing']), ('eposUser', ['arm', 'epos,arm', 'epos', 'financing', 'customer']), ('cic_data', ['lead']), ('ivrUser', []), ('apsUser', ['aps']), ('cicCheckingExtUser', []), ('internal_operation', ['local-cs'])]

I want to create a combination between two lists with the condition:

if (acl value in route_white_list) exist in consumer_white_list:
    combine (route_white_list) and (consumer_white_list)

For example:

With route_white_list[1] = ('atl-card', {'acl': ['pcidss-customer']}) has acl = pcidss-customer

I have two tuples in consumer_white_list include:

('oapi_lp_online', ['financing', 'user-services', 'identity', 'customer', 'pcidss-customer', 'client', 'customerpartner', 'users'])

('superUser', ['client', 'users', 'pcs', 'identity', 'financialPartner', 'pcidss', 'master-data', 'pcidss-customer', 'customerpartner', 'ekyc', 'customer', 'financing'])

Therefore, I create the combination {'atl-card',['oapi_lp_online','superUser']}

Thank you.

Asked By: nistelrooy41001662

||

Answers:

I update my answer

1. Get index position

combineIndex = []
for x in range(len(finalzipRouteConsumer)):
   for y in range(len(finalzipRouteServiceTotal)):
      if finalzipRouteConsumer[x][0]==finalzipRouteServiceTotal[y][0]:
         loopcombineIndex = (y,x)
         combineIndex.append(loopcombineIndex)
print("############### Combine index ##############")
print(combineIndex)
print(len(combineIndex))

2. Combine

for z in range(len(combineIndex)):
   finalzipRouteServiceTotal_combineIndex = combineIndex[z][0]
   finalzipRouteConsumer_combineIndex = combineIndex[z][1]
   combineRouteServiceConsumer =finalzipRouteServiceTotal[finalzipRouteServiceTotal_combineIndex]+finalzipRouteConsumer[finalzipRouteConsumer_combineIndex]
   finalzipRouteServiceTotal[finalzipRouteServiceTotal_combineIndex] = combineRouteServiceConsumer
print("########## After Final combine ##############")
print(finalzipRouteServiceTotal)
print(len(finalzipRouteServiceTotal))
Answered By: nistelrooy41001662
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.