Python Forum
Loop through elements of list and include as value in the dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loop through elements of list and include as value in the dictionary
#4
Still not sure I get it right, but I would get the brokerID list first and then, assign that to each cluster name (as key)
I would do this in list/dict comprehension

brokers = [broker['BrokerNodeInfo']['BrokerId'] for broker in kfk_broker['NodeInfoList']]
clusters = {cl['ClusterName']:brokers[::] for cl in cluster['ClusterInfoList']}
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: Loop through elements of list and include as value in the dictionary - by buran - Jun-13-2020, 05:43 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  help with adding duplicates elements together in a list 2ECC3O 5 2,132 Sep-10-2022, 07:11 AM
Last Post: 2ECC3O
  Unexpected behavior accessing list elements. tonyflute 2 2,305 Apr-09-2021, 02:36 PM
Last Post: tonyflute
  How to find difference between elements in a list? Using beginner Basics only. Anklebiter 8 4,440 Nov-19-2020, 07:43 PM
Last Post: Anklebiter
  Get 5 most unique combinations of elements in a 2D list wanttolearn 1 2,347 Sep-24-2020, 02:26 PM
Last Post: buran
  How can I print the number of unique elements in a list? AnOddGirl 5 3,342 Mar-24-2020, 05:47 AM
Last Post: AnOddGirl
  How can details be dynamically entered into a list and displayed using a dictionary? Pranav 5 2,978 Mar-02-2020, 10:17 AM
Last Post: buran
  Functions returns content of dictionary as sorted list kyletremblay15 1 2,079 Nov-21-2019, 10:06 PM
Last Post: ichabod801
  Extracting elements in a list to form a message using for loop Tony04 2 2,406 Oct-25-2019, 05:55 PM
Last Post: ichabod801
  Sum of elements on the list recursive sev 3 2,601 Jun-20-2019, 02:14 PM
Last Post: sev
  Finding average in dictionary using for loop Rae 4 14,808 May-26-2019, 12:06 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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