Python Forum
having dictionary and list to iterate in for loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
having dictionary and list to iterate in for loop
#1
dic = {3: 0.1, 4: 0.2, 5: 0.1, 6:0.2, 7:0.1, 8:0.2}
ls =  {0.2,   0.1,     0.2,    0.1,   0.2,   0.1}
n = {}


for i, v, l in list(dic.keys()),list(dic.values()),ls:

   add = v + l
   n[i] = add

# expected result {3: 0.3, 4: 0.3, 5: 0.3, 6:0.3, 7:0.3, 8:0.3}
print (n)
I'm trying to use keys, values of dic and entries of ls at the same time, can I do that?
 I'm not sure why it's not correct ?

Wait, I can only have one element after in ?
Reply


Messages In This Thread
having dictionary and list to iterate in for loop - by Annie - Jan-04-2017, 07:50 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sort a list of dictionaries by the only dictionary key Calab 2 646 Apr-29-2024, 04:38 PM
Last Post: Calab
  Dictionary in a list bashage 2 606 Dec-27-2023, 04:04 PM
Last Post: deanhystad
  filtering a list of dictionary as per given criteria jss 5 754 Dec-23-2023, 08:47 AM
Last Post: Gribouillis
  How to add list to dictionary? Kull_Khan 3 1,053 Apr-04-2023, 08:35 AM
Last Post: ClaytonMorrison
  iterate through the dict_values while unpacking the dictionary PeacockOpenminded 3 1,338 Jan-22-2023, 12:44 PM
Last Post: PeacockOpenminded
  check if element is in a list in a dictionary value ambrozote 4 2,042 May-11-2022, 06:05 PM
Last Post: deanhystad
  Dictionary from a list failed, help needed leoahum 7 2,051 Apr-28-2022, 06:59 AM
Last Post: buran
  how to assign items from a list to a dictionary CompleteNewb 3 1,623 Mar-19-2022, 01:25 AM
Last Post: deanhystad
  Python, how to manage multiple data in list or dictionary with calculations and FIFO Mikeardy 8 2,695 Dec-31-2021, 07:47 AM
Last Post: Mikeardy
  For Loop and Use of Brackets to Modify Dictionary in Tic-Tac-Toe Game new_coder_231013 7 2,337 Dec-28-2021, 11:32 AM
Last Post: new_coder_231013

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020