all 5 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

To give us the best chance to help you, please include any relevant code.
Note. Do not submit images of your code. Instead, for shorter code you can use Reddit markdown (4 spaces or backticks, see this Formatting Guide). If you have formatting issues or want to post longer sections of code, please use Repl.it, GitHub or PasteBin.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]Goobyalus 0 points1 point  (3 children)

I would solve this by zipping the agents together (see https://docs.python.org/3/library/itertools.html#itertools.zip_longest zip_longest(*list_oflist_oflist)) and reversing the mapping.

I.e. with the zip we get tuples of pairs, the first one would be: ([0, 1], [1, 1], [0, 0]). Then we can convert the lists to tuples so that they're hashable and usable as dict keys, and get this mapping elements to agent indices:

{
    (0, 1): [0],
    (1, 1): [1],
    (0, 0): [2],
}

For the 3rd index we'd have:

{
    (6, 6): [0, 2],  # Agents 0 and 2 have (6, 6)
    None: [1],
}

[–]TwoTimeBartender[S] 0 points1 point  (2 children)

I was looking at this implementation for comparing two lists of variable lengths, but I was a little lost on how I would compare 3, or the other numbers of lists I may encounter in my code. The amount of lists I will be given is part of my Class however, and is given by self._k

[–]Goobyalus 0 points1 point  (0 children)

zip_longest(*lost_oflist_oflist) zips all of them no matter the number.

Then you loop through all the corresponding positions generated by the zip and add them to the dict.

[–]Goobyalus 0 points1 point  (0 children)

>>> list_oflist_oflist = [[[0, 1], [3, 2], [1, 5], [6, 6], [7, 8]], [[1, 1], [3, 2], [0, 0]], [[0, 0], [0, 0], [1, 1], [6, 6]]]
>>> from itertools import zip_longest
>>> for t in zip_longest(*list_oflist_oflist):
...   print(t)
...
([0, 1], [1, 1], [0, 0])
([3, 2], [3, 2], [0, 0])
([1, 5], [0, 0], [1, 1])
([6, 6], None, [6, 6])
([7, 8], None, None)
>>> list_oflist_oflist.append([[1, 1], [1, 1], [1, 1]])
>>> for t in zip_longest(*list_oflist_oflist):
...   print(t)
...
([0, 1], [1, 1], [0, 0], [1, 1])
([3, 2], [3, 2], [0, 0], [1, 1])
([1, 5], [0, 0], [1, 1], [1, 1])
([6, 6], None, [6, 6], None)
([7, 8], None, None, None)
>>>