checkio Unix Match. Part 1

题目:

  • matches everything
    ? matches any single character
    Input: Two arguments. Both are strings.
    Output: Bool.
    Example:
    unix_match(‘somefile.txt’, ‘’) == True
    unix_match(‘other.exe’, '
    ’) == True
    unix_match(‘my.exe’, ‘*.txt’) == False
    unix_match(‘log1.txt’, ‘log?.txt’) == True
    unix_match(‘log12.txt’, ‘log?.txt’) == False
    unix_match(‘log12.txt’, ‘log??.txt’) == True

链接:
https://py.checkio.org/en/mission/unix-match-part-1/
代码:

def unix_match(filename: str, pattern: str) -> bool:
    a = filename
    b = pattern
    r = True
    if len(b) > len(a):
        r = False
    if '?' in b and '*' not in b:
        if len(a) != len(b): 
    		r = False
    	else:
    		for i in range(0, len(a)):
    		    if a[i] != b[i] and b[i] != '?':
    			    r = False
    for i in b:
        if i != '*' and i!='?' and i not in a:
    		r = False
    if '.' in a:
        x = a.split('.')   
        if '.' in b:
            c = b.split('.')
        	if c[1] != x[1] and c[1] != '*' and '?' not in c[1]:
        		r = False
    return r
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值