Home > Software design >  Arranging a list based on some Condition
Arranging a list based on some Condition

Time:05-06

I have been trying to solve this problem for a while now and really need some help. I am working with Python and was wondering if any of you experts know of any modules that would be able to do this. Here is the explanation. This may be weird to look at as its all dealing with 3,6, and 9, but I explain it so you should understand what I am trying to do.

These were our lists:

group_1 = [3,3,3,3,6,6,3,6,6]
group_2 = [3,3,3,6,6,6,9,9,9]

They added to downwards (RULES: 3 3=6, 6 6=3, 3 6=9, 3 9=3, 6 9=6) like so to get group_3:

group_1 = [3,3,3,3,6,6,3,6,6]
           | | | | | | | | |
           v v v v v v v v v
group_2 = [3,3,3,6,6,6,9,9,9]

group_3 = [6,6,6,9,3,3,3,6,6]

Had group_1 been in a different order, group_3 would have different quantities of 3's,6's, and 9's. So, that being said, if we know ONLY the amounts in groups 1 and 3,

group_1 = [3,3,3,3,3,6,6,6,6]
group_2 = [3,3,3,6,6,6,9,9,9]
group_3 = [3,3,3,6,6,6,6,6,9]

Because, group_3's amount are what they are, and group_2 stays the same, we should be able to figure out or write a code that can tell us the order of group_1.

Any ideas? Anything may help me out, this is really important to me.

Example:

Trying to solve this looks like this (Subtract group_3 from group_2 until the correct quantity of values appears from group_1) Right now I have to guess the order of group_3 but an equation exists out there somewhere: Guess 1(RULES: 3-3=9, 6-6=9, 3-6=6, 6-3=3, 9-3=6, 3-9=3, 9-6=3, 6-9=6, 9-9=9):

    group_3 = [6,6,6,6,6,3,3,3,9]
               | | | | | | | | |
               v v v v v v v v v
    group_2 = [3,3,3,6,6,6,9,9,9]
    group_1 = [3,3,3,9,9,6,3,3,9]

Guess 1 is Incorrect because the values in group_1 do not match the original group_1.

Hope this clears the Confusion.

CodePudding user response:

Use a dictionary that holds the rules.

rules = {(3, 3): 6, (6, 6): 3, (3, 6): 9, (3, 9): 3, (6, 9): 6}

group_3 = [rules[pair] for pair in zip(group_1, group_2)]

CodePudding user response:

you can visit my kaggle account, i create a simple function for your project, i hope that it be helpful :) https://www.kaggle.com/code/salhytaha/simple-function-for-a-low-level-in-python-not-ai

  • Related