我创建一个看起来像这样的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."}
}
}
我想检索“单词”字段的每个值。那怎么可能?
答案 0 :(得分: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