Python Forum
Filter list respecting seniority & no more than 3 same number
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Filter list respecting seniority & no more than 3 same number
#12
Alright ! so a little update :)

I believe i managed to understand most of the content of the code you wrote & tweaking it best i can with the limited knowledge i got in python Shifty

I am confused about the line 9 which is 'assignments = [ ]'

I believe it will refer to the list of the assigned week.
Can i get few pointer on how i am supposed to build that list?
I guess it will need to be built from the result of the code you wrote right?

Also, what is the reference to week_num, what does it do and where does it come from, is it built-in into python or something ?

from collections import OrderedDict

preferences = OrderedDict([('Jean', (1, 2, 3, 4, 5)), ('Claude', (1, 2, 3, 4, 5)),  ('Van', (1, 2, 3, 4, 5)),
                     ('Kung', (1, 2, 3, 4, 5)), ('Fu', (1, 2, 3, 4, 5)), ('Panda', (1, 2, 3, 4, 5)),
                     ('To',(1, 2, 3, 4, 5)), ('Much', (1, 2, 3, 4 , 5)), ('Absolver', (1, 2, 3, 4, 5))])

weeks = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
         31, 32,33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52]

assignments = [ ]

tracking = {week_num: 0 for week_num in weeks}
assignments = [ ]
for preferences in [ ]:
    assignments.append([ ])
    for week_num in preferences:
        if tracking[week_num] < 3:
            assignments[-1].append(week_num)
            tracking[week_num] += 1
            if len(assignments[-1]) == 2:
                break

for key, value in assignments.items() :
    print (key, value)
Reply


Messages In This Thread
RE: Filter list respecting seniority & no more than 3 same number - by Azerate - Sep-01-2017, 04:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Delete strings from a list to create a new only number list Dvdscot 8 1,607 May-01-2023, 09:06 PM
Last Post: deanhystad
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,344 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  TypeError: float() argument must be a string or a number, not 'list' Anldra12 2 4,952 Jul-01-2022, 01:23 PM
Last Post: deanhystad
  Split a number to list and list sum must be number sunny9495 5 2,360 Apr-28-2022, 09:32 AM
Last Post: Dexty
  Divide a number by numbers in a list. Wallen 7 8,135 Feb-12-2022, 01:51 PM
Last Post: deanhystad
  When did the number got included in the list? Frankduc 14 3,225 Feb-03-2022, 03:47 PM
Last Post: Frankduc
  Count number of occurrences of list items in list of tuples t4keheart 1 2,411 Nov-03-2020, 05:37 AM
Last Post: deanhystad
  How do I add a number to every item in a list? john316 2 2,010 Oct-28-2020, 05:29 PM
Last Post: deanhystad
  Print the number of items in a list on ubuntu terminal buttercup 2 1,970 Jul-24-2020, 01:46 PM
Last Post: ndc85430
  Topic: “Filter numbers with a list comprehension” (PyBite #107) Drone4four 4 2,434 Jun-11-2020, 08:31 PM
Last Post: Drone4four

Forum Jump:

User Panel Messages

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