Python Forum
update values in list based on dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
update values in list based on dictionary
#2
I suggest the following improvements
  1. The dictionary has the scores as keys and the teams as values, they want switching so the teams are the keys and the scores are the values.
  2. The first line from the text file you want to skip over it as its a header, to do this you can use next on info_outputfile
  3. 'liverpool' in the file is lower case l, 'Liverpool' in the dictionary has upper case L, one or the other must change so they match.
  4. There is one too many loops, remove the last one
  5. Change the line split variable from l to element
  6. The list indexes are wrong for the last two items from the split.
  7. The error shown does not match the code shown.
Reply


Messages In This Thread
RE: update values in list based on dictionary - by Yoriz - Jun-08-2019, 10:37 PM

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
Question Using Lists as Dictionary Values bfallert 8 411 Apr-21-2024, 06:55 AM
Last Post: Pedroski55
  unable to remove all elements from list based on a condition sg_python 3 488 Jan-27-2024, 04:03 PM
Last Post: deanhystad
  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
  need to compare 2 values in a nested dictionary jss 2 915 Nov-30-2023, 03:17 PM
Last Post: Pedroski55
  Copying the order of another list with identical values gohanhango 7 1,206 Nov-29-2023, 09:17 PM
Last Post: Pedroski55
  Search Excel File with a list of values huzzug 4 1,305 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Comparing List values to get indexes Edward_ 7 1,237 Jun-09-2023, 04:57 PM
Last Post: deanhystad
  Printing specific values out from a dictionary mcoliver88 6 1,481 Apr-12-2023, 08:10 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