0

I have four arrays :

array1 = ["apple","orange","lemon"]
array2 = ["cola","fanta","sprite"]
array3 = ["cookies","sweets","chocolate"]
array4 = ["burger","pizza","pasta"]

What I would like to achieve :

complex_dict = {
'apple':[
          [array2],
          [array3],
          [array4]
],
"orange":[
          [array2],
          [array3],
          [array4]
],
"lemon":[
          [array2],
          [array3],
          [array4]
]}

I tried to use dictionary comprehension:

complex_dict = {a: [[b],[c],[d]] for a,b,c,d in zip(array1,array2,array3,array4)}

Output :

{'apple': [['cola'], ['cookies'], ['burger']], 'orange': [['fanta'], ['sweets'], ['pizza']], 'lemon': [['sprite'], ['chocolate'], ['pasta']]}

Which is different from the one that I would like to achieve. Dear community, kindly ask for your help

1 Answer 1

2

Is this what you want?

array1 = ["apple","orange","lemon"]
array2 = ["cola","fanta","sprite"]
array3 = ["cookies","sweets","chocolate"]
array4 = ["burger","pizza","pasta"]

{ a : [array2, array3, array4] for a in array1}

Returning:

>> {'apple': [
       ['cola', 'fanta', 'sprite'],
       ['cookies', 'sweets', 'chocolate'],
       ['burger', 'pizza', 'pasta']],
    'orange': [
       ['cola', 'fanta', 'sprite'],
       ['cookies', 'sweets', 'chocolate'],
       ['burger', 'pizza', 'pasta']],
    'lemon': [
       ['cola', 'fanta', 'sprite'],
       ['cookies', 'sweets', 'chocolate'],
       ['burger', 'pizza', 'pasta']]}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.