Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if any entries in a list ends with a specified string

Tags:

python

list

So, lets say I want to find the entries that end in foo.

You'd think you do something like:

results = list.endswith("foo")

And then print out the entries that end in the string foo

How would I do this?

like image 760
Ryan Davis Avatar asked Sep 13 '25 06:09

Ryan Davis


1 Answers

The following works, but let's call the list myList:

result = [x for x in myList if x.endswith('foo')]
like image 68
synp Avatar answered Sep 14 '25 20:09

synp