Please ignore secret bonuses. Secret tests do NOT award bonus. Max hw grade is 30+2 bonus efficiency

Do you need help?

Notice Board

Per partecipare al corso di Fondamenti di programmazione 2023-24 loggatevi e attivatelo nella vostra pagina dei corsi preferiti. A quel punto il corso appare nel menù personale cliccando sul proprio avatar. Per i materiali degli anni precedenti seguite lo stesso metodo.

To join the Programming/Lab 2023-24 course, log-on and select it on the my courses page. It will appear on the personal menu of your avatar. For earlier years use the same method.

confronting lists in a loop

G
GuidoG93 (970 points)
6 9 13
in HW8 by (970 points)
recategorized by
hello, I have a list of lists of numbers, that I got with a function for combinations, for example [[1,2,3,4],[1,2,1,2],[3,4,3,4],[2,1,2,1],...]. I was trying to get combinations of those lists, with the condition that if any element in the first sublist is in the second sublist, to pass, if instead we have no elements in common, it continues, and so on until a stop point that I determined.

ex [1,2,1,2] can't have as a next element [2,1,3,4] because they have 1,2 in common, but [3,4,3,4] is instead acceptable.

Unfortunately it seems like every attempt I do doesn't return anything or it returns just a list of all combinations.

Could anyone help me?
323 views
closed

2 Answers

Best answer
l
laertleba (2840 points)
11 28 42
by (2.8k points)
selected by
I have done a similar thing for my homework. You can use two for loops that go throught the same list of lists, then, given two lists of integers check for each of those elements if they are IN the second list. In the case one of the elements is, use Continue, otherwise do what you have to do. I hope I was helpful.
gabriel.bustamante (2540 points)
3 6 20
by (2.5k points)
You could use sets to check whether two lists have no items in common. If a, b are two lists then set(a).isdisjoint(b) will return True if they have no items in common.

The issue could be in how you actually store the valid combinations though.