【发布时间】:2014-04-04 01:50:11
【问题描述】:
我有一个字符串列表,我称之为过滤器。
filter = ["/This/is/an/example", "/Another/example"]
现在我只想从另一个列表中获取以这两个之一开头的字符串(或更多,列表将是动态的)。所以假设我要检查的字符串列表是这样的。
to_check= ["/This/is/an/example/of/what/I/mean", "/Another/example/this/is/", "/This/example", "/Another/freaking/example"]
当我通过过滤器运行它时,我会得到一个返回列表
["/This/is/an/example/of/what/I/mean", "/Another/example/this/is"]
有人知道python是否有办法做我所说的吗?仅从一个列表中获取以另一个列表中的内容开头的字符串?
【问题讨论】:
-
/Another/example_you_may_not_have_expected怎么样?是否以/Another/example开头? -
好收获。我将过滤器调整为“/Another/example/”
标签: python string list filtering