作者detic (dadi)
看板Python
標題[問題] *
時間Tue Dec 27 22:07:40 2016
不好意思請教,我剛接觸python,
想請問在字串中的*(萬用替代字)該如何使用?
比方說
a=["abc","aba","abj","asd","aja"]
想要移除其中頭尾有a的項目,
直觀地想
a.remove("a*a")
.....是不行的....
請問在python中要如何操作我的想法
感謝:)
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 119.14.71.105
※ 文章網址: https://webptt.com/m.aspx?n=bbs/Python/M.1482847663.A.B91.html
1F:推 Sunal: re regular expression 12/27 22:19
2F:→ yjc1: fnmatch 12/27 22:19
3F:推 Yshuan: 就算是RE也是a.*a吧 ... 12/27 22:46
4F:→ kenduest: re 的話 ^a.*a$ 應該更符合需求? 12/28 00:23
5F:→ kenduest: new_a = [i for i in a if re.match("^a.*b$",i)] 這樣? 12/28 00:32
6F:→ kenduest: 上面是抓符合的,稍微改一下加上 not 就變成不符合 12/28 09:42
8F:推 kenduest: glob不是用於檔案搜尋比對嗎? 01/03 11:50