0

I create a tinydb database that looks as such:

{"_default": 
    {"1": {"word": "cat", "definition": "Its an animal."}, 
     "2": {"word": "cat", "definition": "Its an animal."}, 
     "3": {"word": "man", "definition": "has a hand"}, 
     "4": {"word": "girl", "definition": "Its a kid"}, 
     "5": {"word": "superman", "definition": "A hero."}
    }
}

I want to retrieve every value for the field "word". How is that possible?

azro
  • 53,056
  • 7
  • 34
  • 70

1 Answers1

1

You may retrieve all rows, then parse to get the different word field in a set for example

all_rows = db.all()

all_words = {row['word'] for row in all_rows}     # set comprehension
all_words = set(map(lambda x: x['home'], values)) # map operation
azro
  • 53,056
  • 7
  • 34
  • 70