Python Forum
list or dictionary manipulation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
list or dictionary manipulation
#1
So here's the skinny. I am new to python, I'm new to JavaScript. I've been writing bash scripts for a while now. So I have some knowledge but not where it needs to be to do what I want. So I'll state my question, but I'd prefer tips, what to read, where to find examples, or example codes. I'd rather not get an answer that is the full code of what I'm wanting to do. That discourages learning.

I'm trying to create a list and manipulate it through a function. So at work I have to assign tickets to a total of 8 guys. But I need an easy way to keep up with how many tickets each guy has been assigned. Not the ticket number, but just a "tally" mark for each ticket he has been assigned. I've been writing down there names and putting a tally mark each time I've assigned a ticket but that is tedious.

I'd like the code to keep up with this and when I run it, the code will tell me who is up next in line to have a ticket assigned to them. Not randomly. It needs to tell me who to assign it to by who has the least amount of tickets assigned to them. I'm not 100% sure how to go about this. Any help would be appreciated.
Reply
#2
You might try starting here: Free-Python-Resources
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#3
Sparkz_alot,

Thanks. I've gone through the Codecademy.com training for Python. I think my biggest issue now is figuring out exactly what I need it to do to achieve the results I'm looking for. I'm gonna go through some of the other courses listed in the other post also.
Reply
#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
#5
ichabod801,

Thanks for the tips. I was thinking a dictionary would be the way to go, but because of my lack of experience I kept doubting myself. Also, I've never heard of the defaultdict, so I'll have to look in to that. But it sounds like it will be helpful.
Reply
#6
Definitely look at the collections module. It's one of the more useful modules out there without an obvious use. Another one is functools, although I don't think it has application to this project.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Dictionary in a list bashage 2 539 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
  How to add list to dictionary? Kull_Khan 3 998 Apr-04-2023, 08:35 AM
Last Post: ClaytonMorrison
  check if element is in a list in a dictionary value ambrozote 4 1,962 May-11-2022, 06:05 PM
Last Post: deanhystad
  Dictionary from a list failed, help needed leoahum 7 1,955 Apr-28-2022, 06:59 AM
Last Post: buran
  how to assign items from a list to a dictionary CompleteNewb 3 1,564 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,594 Dec-31-2021, 07:47 AM
Last Post: Mikeardy
  Problem in list manipulation CyKlop 6 2,281 Oct-18-2021, 09:03 AM
Last Post: DeaD_EyE
  Class-Aggregation and creating a list/dictionary IoannisDem 1 1,917 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