0

我创建了一个如下所示的 tinydb 数据库:

{"_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."}
    }
}

我想检索字段“word”的每个值。这怎么可能?

4

1 回答 1

0

例如,您可以检索所有行,然后解析以获取不同的word字段set

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
于 2019-12-07T11:26:52.547 回答