Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dict and Isin
#2
What is Isin? ISIN as is in International Securities Identification Number or "Is this in that?"

You want to parse an address to find the city, find a driver for that city, and then append the driver's name to the address? Is that what you want to do?

An easy way is to search for all the keys in your driver database.
drivers = {
    "John":"New York",
    "Tim":"Los Angeles"
}

addresses = [
    "47 W 13th St, New York, NY 10011, USA",
    "1419 Westwood Blvd, Los Angeles | CA 90024-491",
    "1222 S 27th St, Lincoln, NE 68502, USA"
]

for address in addresses:
    for driver, city in drivers.items():
        if city in address:
            print(f"{address} {driver}")
            break
    else:
        print(f"{address} No Driver Available")
Output:
47 W 13th St, New York, NY 10011, USA John 1419 Westwood Blvd, Los Angeles | CA 90024-491 Tim 1222 S 27th St, Lincoln, NE 68502, USA No Driver Available
This becomes inefficient if you have lots of addresses and lots of drivers. If that is the case you should parse the address to extract the city and have a dictionary of cities (keys) and drivers (values).

Both of these fail if you have the same city name used for different cities like Portland Maine and Portland Oregon.
Reply


Messages In This Thread
Dict and Isin - by JonahPython - Nov-03-2021, 02:51 AM
RE: Dict and Isin - by deanhystad - Nov-05-2021, 07:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Using Regex Expression With Isin in Python eddywinch82 0 2,390 Apr-04-2021, 06:25 PM
Last Post: eddywinch82
  Sort a dict in dict cherry_cherry 4 102,373 Apr-08-2020, 12:25 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020