How to extract data except for None in db.

Asked 2 years ago, Updated 2 years ago, 13 views

for c in db.fruit.find({'Value': 5}):
    print(c['fName'])

In db.fruit, Fruit names (fName) and Each fruit contains an integer value between 0 and 5. (If you haven't evaluated the value of the product yet, leave the space blank and the value is None!!)

The code on the first line is the code I used to find the fruit name (fName) with a value of 5 Except for fruits that have not been valued (=excluding items with a value of None), If you want to find all the rest of the fruit names, How do I change the {'Value':5} part??

python

2022-09-20 18:01

1 Answers

I don't know exactly how to handle db, but... I think it's in the dict format.

If db.fruit has fName and Value, shouldn't it be as follows?

for c in db.fruit:
    if c['Value'].isalnum():
        print(c['fName'])

Or

for c in db.fruit:
    if c['Value'] is not None:
        print(c['fName'])


2022-09-20 18:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.