-2

Currently, I have the following two lists:

list1 = ['DB00619', 'DB01048', 'DB14093', 'DB00173', 'DB00734', 'DB00218', 'DB05196', 'DB09095', 'DB01053', 'DB00274']
list2 = [['Imatinib', 'Imatinibum'], ['Abacavir', 'ABC '], [], ['6-Aminopurine', 'Adenin', 'Vitamin B4'], ['Risperidona', 'Rispéridone', 'Risperidone', 'Risperidonum'], ['Moxifloxacin', 'Moxifloxacino'], [], ['Diflucortolona', 'Diflucortolone', 'Diflucortolonum'], ['Bencilpenicilina', 'Bensylpenicillin', 'Benzyl benicillin', 'Benzylpenicillin', 'Benzylpénicilline', 'Benzylpenicillinic acid', 'Benzylpenicillinum', 'Penicillin G'], ['Cefmetazole', 'Cefmetazolo', 'Cefmetazolum']]

My question is how can I combine these two lists and create a library, like the following?

e.g.

mylib = {'DB00619': ['Imatinib', 'Imatinibum'], etc.....}
Aviv Yaniv
  • 6,188
  • 3
  • 7
  • 22

1 Answers1

0

you can use the zip function which takes the respective elements in order and combines them. It returns them as tuples so you need to use dict constructor to convert them to a dictionary:

mylib = dict(zip(list1, list2))
T K
  • 618
  • 7
  • 20
  • Thank you! That worked perfectly! Do you know if its possible to a dictionary with three different lists? With the first list being the key and then the next two lists are values? – Yusuf Cattaneo Sep 13 '20 at 18:37
  • I think that is not possible as dict can only accept tuples with two fields, you can use zip with any number of arguments and then convert it to a tuple and then process that tuple as you please. That is how I would do it. – mohamed alattal Sep 13 '20 at 18:41