Python Forum
list or dictionary manipulation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
list or dictionary manipulation
#4
Store it in a dictionary, and increment it every time someone gets a ticket:

tickets['Bob'] += 1
A defautldict from the collections module will work well for this, since you won't have to initialize it for new staff. Then:

ticket_counts = [(count, name) for name, count in tickets.items()]
ticket_counts.sort()
print(ticket_counts[0][1])
That will get you the name of the person with the least tickets. Technically it will give you the person with the first name alphabetically of those with the lowest ticket count. You could use print(ticket_counts[:3]) to see the top three if you wanted.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
list or dictionary manipulation - by dtigue - Jul-20-2017, 08:57 PM
RE: list or dictionary manipulation - by dtigue - Jul-20-2017, 09:18 PM
RE: list or dictionary manipulation - by ichabod801 - Jul-21-2017, 02:38 AM
RE: list or dictionary manipulation - by dtigue - Jul-21-2017, 03:10 PM
RE: list or dictionary manipulation - by ichabod801 - Jul-21-2017, 03:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sort a list of dictionaries by the only dictionary key Calab 2 803 Apr-29-2024, 04:38 PM
Last Post: Calab
  Dictionary in a list bashage 2 715 Dec-27-2023, 04:04 PM
Last Post: deanhystad
  filtering a list of dictionary as per given criteria jss 5 897 Dec-23-2023, 08:47 AM
Last Post: Gribouillis
  How to add list to dictionary? Kull_Khan 3 1,168 Apr-04-2023, 08:35 AM
Last Post: ClaytonMorrison
  check if element is in a list in a dictionary value ambrozote 4 2,199 May-11-2022, 06:05 PM
Last Post: deanhystad
  Dictionary from a list failed, help needed leoahum 7 2,215 Apr-28-2022, 06:59 AM
Last Post: buran
  how to assign items from a list to a dictionary CompleteNewb 3 1,763 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,854 Dec-31-2021, 07:47 AM
Last Post: Mikeardy
  Problem in list manipulation CyKlop 6 2,501 Oct-18-2021, 09:03 AM
Last Post: DeaD_EyE
  Class-Aggregation and creating a list/dictionary IoannisDem 1 2,063 Oct-03-2021, 05:16 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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