Created
January 17, 2023 13:32
-
-
Save beigna/f015dcedc84e241bd72c8ea90b1dc01a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
repetidos = [1, 2, 3, "1", "2", "3", 3, 4, 5] | |
r = [1, "5", 2, "3"] | |
d_str = '{"valor":125.3,"codigo":123}' | |
def _elements_to_int(elements): | |
return [int(e) for e in elements] | |
# Paso 1 - Quedarse con los valores únicos | |
repetidos_unicos = set(_elements_to_int(repetidos)) | |
print(f'Los valores únicos de "repetidos" son: {repetidos_unicos}\n') | |
# Paso 2 - Valores en común | |
valores_comunes = set(_elements_to_int(r)).intersection(repetidos_unicos) | |
print(f'Los valores en común entre "r" y "repetidos" son: {valores_comunes}\n') | |
# Paso 3 - Convertir String a Diccionario | |
d_dict = json.loads(d_str) | |
print(f'{d_dict} es {type(d_dict)}\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment