jueves, 1 de agosto de 2024

Using list and tuple for grouping dict based on a conditional value

# Online Python compiler (interpreter) to run Python online.

# Write Python 3 code in this online editor and 


st={'Ambiorix':90,'Katherine':89,'Armando':88,'Ruth':77,'Rosa':60,'Pedro':63,'Maria':74,'Jesus':100,'Juan':99}



tp=[tp for tp in st.items()]

print(tp)


for a in tp:

    if a[1]  >=70 and a[1]  <=79:

        print(a)

        

        

print('----------------')


def getrange(st,z,y):

    tp=[tp for tp in st.items()]

    

    for a in tp:

       if a[1]  >=z and a[1]  <=y:

        print(a)



getrange(st,0,69)

    

[('Ambiorix', 90), ('Katherine', 89), ('Armando', 88), ('Ruth', 77), ('Rosa', 60), ('Pedro', 63), ('Maria', 74), ('Jesus', 100), ('Juan', 99)]
('Ruth', 77)
('Maria', 74)
----------------
('Rosa', 60)
('Pedro', 63)

No hay comentarios:

Publicar un comentario