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

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

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

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,847 questions

51,768 answers

573 users

How to combine two nested lists into a tuple list with Python

2 Answers

0 votes
lst1 = [[1, 2, 3, 4], [5, 6], [7]] 
lst2 = [['a', 'b', 'c', 'd'], ['e', 'f'], ['g']] 

lst_tpl = [(a, b) for x, y in zip(lst1, lst2) for a, b in zip(x, y)] 
  
print(lst_tpl) 
  
  
  
'''
run:
  
[(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e'), (6, 'f'), (7, 'g')]
  
'''

 



answered Dec 24, 2019 by avibootz
0 votes
from itertools import chain 

lst1 = [[1, 2, 3, 4], [5, 6], [7]] 
lst2 = [['a', 'b', 'c', 'd'], ['e', 'f'], ['g']] 

lst_tpl = list(zip(chain.from_iterable(lst1), chain.from_iterable(lst2))) 
  
print(lst_tpl) 
  
  
  
'''
run:
  
[(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e'), (6, 'f'), (7, 'g')]
  
'''

 



answered Dec 24, 2019 by avibootz
...