Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

zip four lists to create dictionary with keys from two lists and values from another two lists

I have four lists:

list_a = ['hello', 'yes', 'you']
list_a_ind = [0, 1, 2]
list_b = ['he', 'here', 'great'] 
list_b_ind = [1, 2, 3]

I want to create a dictionary with combined index as keys and combined elements as values, result as below:

dictionary_ab = {(0,1): ('hello', 'he'), 
                 (1,2): ('yes', 'here'), 
                 (2,3): ('you', 'great)}

what’s the fastest way to do it?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This snippet will do the trick:

dict(zip(zip(list_a_ind, list_b_ind), zip(list_a, list_b)))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading