Home > Mobile >  how do i perform a list operation for bellow lists
how do i perform a list operation for bellow lists

Time:10-27

lst = ['mango','banana','Watermelon','Papaya']
lst2 = [200,100,500]

my lists look like this. I need to access these parameters like first element 1 lst 1 element 2nd list.

I want output like in dictionary.

my code like this I access all elements in that:

dict = { "fruit": lst[1], "price": lst2[1] }

I need a output like this dict but I get only one I defined for each element separately I want my output like this but I got only one dict

my output {fruit: mango,price=200}

expected output: [{fruit: mango,prise=200},{ fruit: 'banana',prise: 100}...]

CodePudding user response:

If I understand your question correctly, here a one-liner:

output = [{"fruit": f, "price": p} for f, p in zip(lst, lst2)]
  • Related