主题 例如:
array = ['value1', 'value2', 'value3', 'value4', ...(here is many values like value5, value6, value7, value49 etc.)..., 'value50' 'something', 'something2']
我应该从该数组中删除value *。我怎样才能做到这一点?
使用列表推导,筛选出以value
以下内容开头的值:
>>> array = ['value1', 'value2', 'value3', 'value4', 'value50', 'something', 'something2']
>>> array = [x for x in array if not x.startswith('value')] # NOTE: used `not`
>>> array
['something', 'something2']
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句