+ 1

How to access only the values ​​of a dictionary in python or JavaScript? I know there was a keyword to only access values ​​but

ovejas = [ { 'name': 'Noa', 'color': 'azul' }, { 'name': 'Euge', 'color': 'rojo' }, { 'name': 'Navidad', 'color': 'rojo' }, { 'name': 'Ki Na Ma', 'color': 'rojo'}, { 'name': 'AAAAAaaaaa', 'color': 'rojo' }, { 'name': 'Nnnnnnnn', 'color': 'rojo'} ]

5th Sep 2022, 7:04 PM
Josué Varela
Josué Varela - avatar
3 Respuestas
+ 1
To get only values in JS, you can use Object.values(). Example: const testObj = { name: ‘dude’, age: 21 }; const vals = Object.values(testObj); // vals is now [‘dude’, 21]
5th Sep 2022, 9:18 PM
Hazmat
Hazmat - avatar
0
In python, I remember it was values​​(dictionary) or something, but I forgot
5th Sep 2022, 7:07 PM
Josué Varela
Josué Varela - avatar
- 1
for o in ovejas: if o["color"] == 'rojo': nm = o["name"].lower() if "n" in nm and "a" in nm: print( nm )
5th Sep 2022, 9:18 PM
SoloProg
SoloProg - avatar