在Python中,如何使用模糊匹配獲取列表中的項目位置(使用list.index
)?Python:使用正則表達式獲取列表索引?
例如,如何獲得以下列表中*berry
表格的所有水果的索引?
fruit_list = ['raspberry', 'apple', 'strawberry']
# Is it possible to do something like the following?
berry_fruit_at_positions = fruit_list.index('*berry')
任何人有任何想法?
這不是一個正則表達式。 – delnan 2010-11-10 15:28:39
正則表達式也不是模糊的。事實恰恰相反:他們非常嚴格和精確。 – 2010-11-10 16:02:29