We are to search collection and find businesses in the county from countyToSearch. Save the name, full address, county and state to saveLocation1
How it is currently is not correct. I dont really understand the filter()
def FindBusinessBasedOnCounty(countyToSearch, saveLocation1, collection):
c = collection.filter(lambda user: user['county'] == countyToSearch)
f = open(saveLocation1, 'w')
for bus in c:
f.write(bus["Name"] + "$" + bus["FullAddress"] + "$" + bus["County"] + "$" + bus["State"] + "\n")
f.close()
edit: I want the result to be the rows in database, where the countyname is equal to countyToSearch.
I do not see you collection example, but what I see is :
filter should be used as:
c = filter(lambda user: user['county'] == countyToSearch, collection)
you have uppercase County
and lower case county
.
In addition, you have to use with open(..)
and not open() ... close()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.