fruit_list = ['raspberry', 'apple', 'strawberry']
# Is it possible to do something like the following?
berry_fruit_at_positions = fruit_list.index('*berry')
import re
fruit_list = ['raspberry', 'apple', 'strawberry']
def grep(yourlist, yourstring):
ide = [i for i, item in enumerate(yourlist) if re.search(yourstring, item)]
return ide
grep(fruit_list, "berry$")
对于正则表达式:
如果没有正则表达式:
有一个功能:
尝试:
返回:
根据您的匹配需要,用不同的逻辑替换
endswith
。相关问题 更多 >
编程相关推荐