0

Trying to implement the logic to perform a search and find the string in list that matched the word which is at the end of the string. below is the two cases where i'm trying to find the table in the list. Split approach didnt help to meet the expected value.

searchtable='customer' # Scenario 1
# searchtable = 'customer_address' # Scenario 2
list  = ['etl_load_customer', 'etl_load_customer_email', 'etl_load_customer_address', 'bi_load_customer_address_location']

for value in list:
    if searchtable in value:  
        print(value)

Scenario 1 : search for 'customer' table

# current output
etl_load_customer

# Expected output
etl_load_customer
etl_load_customer_email
etl_load_customer_address
bi_load_customer_address_location

Scenario 2 search for 'customer_address' table

# current output
etl_load_customer_address
bi_load_customer_address_location

# Expected output
etl_load_customer_address
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
E88
  • 97
  • 1
  • 9
  • 1
    Your question is not clear. In the first scenario you might have switched the current and expected and in the second scenario why don't you expect `bi_load_customer_address_location`? It also has `customer_address` in it – Tomerikoo Jun 01 '21 at 17:29
  • 1
    Have a look at [`str.endswith()`](https://docs.python.org/3/library/stdtypes.html#str.endswith). – 001 Jun 01 '21 at 17:31

0 Answers0