Learning Python

jueves, 12 de diciembre de 2024

getting only str o int values from a dict

 >>> r

{'Name': 'Ambiorix', 'age': 34}

>>> {r[a]:a for a in r if type(r[a])==int}

{34: 'age'}

>>> {r[a]:a for a in r if type(r[a])==str}

{'Ambiorix': 'Name'}


Publicado por Ambiorix Rodriguez en 17:40
Enviar por correo electrónicoEscribe un blogCompartir en XCompartir con FacebookCompartir en Pinterest

No hay comentarios:

Publicar un comentario

Entrada más reciente Entrada antigua Inicio
Suscribirse a: Enviar comentarios (Atom)

Archivo del blog

  • ►  2025 (9)
    • ►  mayo (1)
    • ►  abril (1)
    • ►  marzo (1)
    • ►  febrero (2)
    • ►  enero (4)
  • ▼  2024 (67)
    • ▼  diciembre (5)
      • Switch Match
      • OpenAI API Realtime TTS and Speech to Text
      • getting key from a dict based on a value
      • getting only str o int values from a dict
      • dict practice
    • ►  noviembre (5)
    • ►  octubre (12)
    • ►  septiembre (14)
    • ►  agosto (14)
    • ►  julio (11)
    • ►  junio (6)
  • ►  2023 (3)
    • ►  octubre (1)
    • ►  marzo (1)
    • ►  febrero (1)
  • ►  2022 (1)
    • ►  julio (1)
  • ►  2021 (2)
    • ►  junio (1)
    • ►  marzo (1)
  • ►  2020 (2)
    • ►  julio (1)
    • ►  febrero (1)
  • ►  2019 (7)
    • ►  agosto (1)
    • ►  julio (3)
    • ►  mayo (1)
    • ►  marzo (2)
  • ►  2018 (57)
    • ►  diciembre (3)
    • ►  noviembre (1)
    • ►  octubre (1)
    • ►  junio (2)
    • ►  abril (1)
    • ►  marzo (5)
    • ►  febrero (3)
    • ►  enero (41)
Tema Sencillo. Con la tecnología de Blogger.