[Python] First occurrence of element in a dictionary of sets

Discussão em 'Python' iniciado por Stack, Março 13, 2025.

  1. Stack

    Stack Membro Participativo

    Given is a dictionary of sets that are contained in a list. What would be a pythonic way to get the key of the first appearance of an element in a set. Do this for all elements!

    Example: Given is the dictionary d and element 510. The answer would be that for key 343 this element appears first in d. This shall be repeated for all values in the sets of d.

    d={
    100: [{406, 491, 440, 448},{590, 633, 560, 564, 651, 681}],
    343: [{366, 412, 440},{448, 491, 510}, {557, 560, 544, 564, 633, 681}],
    423: [{440, 448, 491, 510, 544, 557, 564, 681}],
    433: [{412, 440, 448, 491},{536, 544, 510, 557, 560, 564}],
    493: [{1286, 1285, 1357}]
    }

    Continue reading...

Compartilhe esta Página