Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Disclosure: My content contains affiliate links.

43,239 questions

56,142 answers

573 users

How to merge corresponding sublists from two different lists in Python

3 Answers

0 votes
def MergeCorrespondingSublists(lst1, lst2):
    return [[i + j for i, j in zip(x, y)]
                 for x, y in zip(lst1, lst2)]
     
lst1 = [['1-', '2-', '3-'], ['4-', '5-', '6-', '7-']]
lst2 = [['python', 'c', 'c++'], ['c#', 'rust', 'java', 'php']]

lst = MergeCorrespondingSublists(lst1, lst2)

print(lst)




'''
run:

[['1-python', '2-c', '3-c++'], ['4-c#', '5-rust', '6-java', '7-php']]

'''

 



answered Mar 17, 2023 by avibootz
0 votes
from operator import concat

def MergeCorrespondingSublists(lst1, lst2):
    return [list(map(concat, i, j)) for i, j in zip(lst1, lst2)]
     
lst1 = [['+', '+', '-'], ['+', '-', '+', '+']]
lst2 = [['python', 'c', 'c++'], ['c#', 'rust', 'java', 'php']]

lst = MergeCorrespondingSublists(lst1, lst2)

print(lst)




'''
run:

[['+python', '+c', '-c++'], ['+c#', '-rust', '+java', '+php']]

'''


 



answered Mar 17, 2023 by avibootz
0 votes
from operator import concat

def MergeCorrespondingSublists(lst1, lst2):
    return [list(map(lambda x, y: x + y, x, y)) for x, y in zip(lst1, lst2)]
     
lst1 = [['+', '+', '-'], ['+', '-', '+', '+']]
lst2 = [['python', 'c', 'c++'], ['c#', 'rust', 'java', 'php']]

lst = MergeCorrespondingSublists(lst1, lst2)

print(lst)




'''
run:

[['+python', '+c', '-c++'], ['+c#', '-rust', '+java', '+php']]

'''

 



answered Mar 17, 2023 by avibootz

Related questions

1 answer 246 views
...