How to find the python list item that start with

后端 未结 3 575
庸人自扰
庸人自扰 2020-12-14 12:32

I have the list that contains some items like:

\"GFS01_06-13-2017 05-10-18-38.csv\"
\"Metadata_GFS01_06-13-2017 05-10-18-38.csv\"

How to fi

3条回答
  •  鱼传尺愫
    2020-12-14 12:59

    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)
    

提交回复
热议问题