Python Forum
how to assign items from a list to a dictionary
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to assign items from a list to a dictionary
#1
How can i simplify this code?

listplayers = [['player1', 5,1,300,100],['player2', 10,5,650,150],['player3', 17,6,1100,1050]]
dictionary  = {
    'playersname':[]
    'totalwin':[]
    'totalloss':[]
    }

for x in listplayers:
    dictionary['playersname'].append(x[0])
    dictionary['totalwins'].append(x[1])
    dictionary['totalloss'].append(x[2])
i know it seems pretty simplified now but if my dictionary and my x has 40 items, it gets pretty tedious to write
Reply


Messages In This Thread
how to assign items from a list to a dictionary - by CompleteNewb - Mar-18-2022, 10:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to parse and group hierarchical list items from an unindented string in Python? ann23fr 0 179 Mar-27-2024, 01:16 PM
Last Post: ann23fr
  Dictionary in a list bashage 2 540 Dec-27-2023, 04:04 PM
Last Post: deanhystad
  filtering a list of dictionary as per given criteria jss 5 666 Dec-23-2023, 08:47 AM
Last Post: Gribouillis
  Sort a list of dictionaries by the only dictionary key Calab 1 488 Oct-27-2023, 03:03 PM
Last Post: buran
  Why do I have to repeat items in list slices in order to make this work? Pythonica 7 1,321 May-22-2023, 10:39 PM
Last Post: ICanIBB
  How to add list to dictionary? Kull_Khan 3 998 Apr-04-2023, 08:35 AM
Last Post: ClaytonMorrison
  Finding combinations of list of items (30 or so) LynnS 1 871 Jan-25-2023, 02:57 PM
Last Post: deanhystad
  For Word, Count in List (Counts.Items()) new_coder_231013 6 2,574 Jul-21-2022, 02:51 PM
Last Post: new_coder_231013
  How to get list of exactly 10 items? Mark17 1 2,503 May-26-2022, 01:37 PM
Last Post: Mark17
  check if element is in a list in a dictionary value ambrozote 4 1,962 May-11-2022, 06:05 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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