0

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.

4

1 回答 1

0

我没有看到您的收藏示例,但我看到的是:

  1. 过滤器应用作:

    c = filter(lambda user: user['county'] == countyToSearch, collection)
    
  2. 你有大写County和小写county

  3. 此外,您必须使用with open(..)而不是open() ... close()

于 2020-11-20T14:42:22.253 回答