+ 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'} ]
3 Answers
+ 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]
0
In python, I remember it was values(dictionary) or something, but I forgot
- 1
for o in ovejas:
if o["color"] == 'rojo':
nm = o["name"].lower()
if "n" in nm and "a" in nm:
print( nm )