I am search through a list of lists like this ...
srchList = [ ['Gloucestershire', 'Tewkesbury', '324225'], ['Gloucestershire', 'Tirley', '353925'], ['Gloucestershire', 'Westbury Court Garden', '354153'], ['Gloucestershire', 'Westonbirt', '354163'], ['Gloucestershire', 'Winchcombe', '354244'], ['Gloucestershire', 'Withington, '354270'], ['Gloucestershire', 'Woodchester Park (Nt)', '354288'], ['Gloucestershire', 'Wotton', '354320'], ['Greater London', 'Tennis Club Wimbledon', '324383'], ['Greater London', 'Arsenal F.C.', '350150'], ['Greater London', 'Barking', '324164'], ['Greater London', 'Barnet', '324151'],
['Greater London', 'Beckton', '350286'], ['Greater London', 'Bexley', '350413'] ]
In order to select those in London, I have to enter "Greater London"
I have evaded problems with capitalisation with .upper()
but how can I get a hit
if I just enter a partial string, such as "london"
or "Gloucester"
?
This is my current code ...
result = [region for region in srchList if region[0].upper() == search_item.upper()]
if result == []:
print("Search item not found")
else:
print(result)