How to check if string ends with one of the strings from a list?
str_list = ['aaa', 'bbb', 'ccc', 'ddd'] # list of items str_test = 'testccc' # string need to test for str_item in str_list: if str_test.endswith(str_item): print("found") break # loop ends when result found else: print("not found")
Sample output of above program.
not found
not found
found
2019-07-11T11:40:25+05:30
2019-07-11T11:40:25+05:30
Amit Arora
Amit Arora
Python Programming Tutorial
Python
Practical Solution