How to find the python list item that start with

If you really want the string output like this "GFS01_06-13-2017 05-10-18-38.csv","GFS01_xxx-xx-xx.csv", you could try this:

', '.join([item for item in myList if item.startswith('GFS01_')])

Or with quotes

', '.join(['"%s"' % item for item in myList if item.startswith('GFS01_')])

Filtering of list will gives you list again and that needs to be handled as per you requirement then.


You should try something like this :

[item for item in my_list if item.startswith('GFS01_')]

where "my_list" is your list of items.


You have several options, but most obvious are:

Using list comprehension with a condition:

result = [i for i in some_list if i.startswith('GFS01_')]

Using filter (which returns iterator)

result = filter(lambda x: x.startswith('GFS01_'), some_list)

Tags:

Python