Python Forum
Conceptualizing modulus. How to compare & communicate with values in a Dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Conceptualizing modulus. How to compare & communicate with values in a Dictionary
#7
To find highest and lowest, sort them.
x = {'001':['Grex','22','40'], '002':['C-Paul','02' ,'88'], '003':['Aquille','11','76']}

print('By Name', dict(sorted(x.items(), key=lambda item: item[1])))

print('By Personality', dict(sorted(x.items(), key=lambda item: item[1][1])))

print('By Ability', dict(sorted(x.items(), key=lambda item: item[1][2])))
As for efficient access, maybe you want to create 2 dictionaries. One keyed by ID ('001?) and another by name.
Reply


Messages In This Thread
RE: Conceptualizing modulus. How to compare & communicate with values in a Dictionary - by deanhystad - Feb-28-2021, 10:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Using Lists as Dictionary Values bfallert 8 402 Apr-21-2024, 06:55 AM
Last Post: Pedroski55
  How to communicate between Electron Framework and python Abdul_Rafey 0 236 Mar-09-2024, 12:18 PM
Last Post: Abdul_Rafey
  cmath.rect accepts a negative modulus JMB 2 360 Jan-17-2024, 08:00 PM
Last Post: JMB
  need to compare 2 values in a nested dictionary jss 2 900 Nov-30-2023, 03:17 PM
Last Post: Pedroski55
  Loop through values and compare edroche3rd 6 731 Oct-18-2023, 04:04 PM
Last Post: edroche3rd
  Trying to compare string values in an if statement israelsattleen 1 576 Jul-08-2023, 03:49 PM
Last Post: deanhystad
  Printing specific values out from a dictionary mcoliver88 6 1,476 Apr-12-2023, 08:10 PM
Last Post: deanhystad
  Compare variable with values in a file paulo79 1 1,145 Apr-22-2022, 03:16 AM
Last Post: Pedroski55
Question How to print each possible permutation in a dictionary that has arrays as values? noahverner1995 2 1,778 Dec-27-2021, 03:43 AM
Last Post: noahverner1995
  Getting values from a dictionary brunolelli 5 3,646 Mar-31-2021, 11:57 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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