#πŸ”’ I have a list of tuples (each tuple contains a nested 3-tuple and an integer) and need to sort it

92 messages Β· Page 1 of 1 (latest)

calm blade
#

Each index in the nested tuple is only allowed to use a value once, how do i minimise the amount of values that miss out

carmine glenBOT
#

@calm blade

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

calm blade
#

data looks like this but the numbers change through the list ((1, 2, 3), 4)

tacit fossil
#

Not quite sure what you're asking

calm blade
#

ill give example

#
[((0, 1, 2, 3), 5), ((0, 1, 2), 4), ((0, 1, 3), 4), ((0, 2, 3), 4), ((1, 2, 3), 4)]
#

data can look like that

tacit fossil
#

why does the first tuple have 4 values?

calm blade
#

always a 3 or 4 tuple i messed up the title on this

tacit fossil
#

ok

calm blade
#

but i want to maximise the amount of numbers used in the 3/4 tuples

#

each integer can only be used once

tacit fossil
#

I'm not sure what you mean by maximising the amount of numbers used

calm blade
#

if i use (0, 1, 2, 3) the numbers 0, 1, 2, 3 cannot be used in the next one

#

so (0,1,2,3) and (4,5,6) is a possible combination

#

but (0,1,2,3) and (0, 5, 6) isnt because 0 has already been used

tacit fossil
#

how many valid numbers are there?

#

6?

calm blade
calm blade
#

imagine each number is an id

#

for a student or something

tacit fossil
#

this is a lot more complex than just a simple sort

calm blade
#

and im making study groups

#

so each student can only be alocated to 1 group

tacit fossil
#

you basically need to gather how many groups are needed, and how many available IDs there are

calm blade
#

it doesnt matter how many groups are made

#

4 groups of 4 is better than 5 groups of 3

tacit fossil
#

it does because that changes how often each ID may be used

calm blade
#

each id can only be used once

tacit fossil
#

you have a fixed number of students?

calm blade
#

yeah a fixed number of possible study groups

#

some students dont get along

calm blade
#

(student, student, student), irrelevant number

#

i want to minimise the amount of left out students

tacit fossil
#

but 1 student can be in more than 1 group?

calm blade
#

no

tacit fossil
calm blade
#

if there was ((4,5,6), irrelevant number) appended to it then it could be 7

#

but you cant reuse students

tacit fossil
#

Is this for an assignment? Can you share the writeup for it?

calm blade
#

sure

#

In this task you will finally allocate the Zoomerbinis to their study groups!

Write a function alloc_study_groups(zbinis) where the parameter zbinis is a list of Zoomerbinis, each represented as a (type_id, subjects) tuple (this is again of the same form as in the previous two tasks). The function should compute a set of groups of zbinis such that the number of Zoomerbinis without a group is minimised. We call this an optimal grouping.

#

and then it goes into detail about how it should be sorted in cases but i think i can do that part

#

heres an example call

#
[(0, 3, 4, 5), (1, 2, 6)]
#

i have a way to generate all possible study groups from the first one

#

a function generates a list of it

tacit fossil
#

but that means you should know ahead of time how many IDs there will be

tacit fossil
calm blade
#
[((0, 3, 4, 5), 8), ((0, 3, 4), 7), ((0, 3, 5), 7), ((0, 4, 5), 7), ((3, 4, 5), 7), ((1, 2, 6), 4)]
tacit fossil
#

so for example if you have 20 people, you have to make as many groups of 3/4 as possible?

calm blade
#

generated by function

calm blade
#

i mean its limited to 10 for memory reasons

#

but 10 students need as many to be in a group

tacit fossil
#

so always a 3, 3, 4?

calm blade
calm blade
calm blade
calm blade
#

output*

tacit fossil
#

I'd almost just brute force the answer at this point. Shuffle groups until everyone is happy

calm blade
#

yeah i might have to

calm blade
tacit fossil
calm blade
#

yeah

calm blade
#

all possible groups

#

not every student gets along

#

i have a function that is imported from a hidden library that return all possible groups

tacit fossil
#

ok so a group you create has to be one of those

calm blade
#

they are the possible groups

#

the number after thr group is used later but doesnt really matter for this part

calm blade
tacit fossil
#

so why not just use those? Why do you even have to generate anything?

#

Just pull valid groups from that list

calm blade
#

that list changes depending on input

#

i input 10 students aswell as classes they take

#

and it outputs the possible groups

#

it knows what students get along

tacit fossil
#

Alright I'm lost then

calm blade
#

that takes this

#
[(198, ['FoC', 'Logic']), (138, ['Calc 1']), (14, ['Calc 1']), (66, ['FoC', 'Logic']), (10, ['FoC', 'Logic']), (142, ['FoC', 'Logic']), (66, ['Calc 1'])]
#

and return the list of all possible groups

#

198 becomes 0, 138 becomes 1 and so on

calm blade
carmine glenBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.