ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

2021 fall cs61a hw09

2022-04-26 13:31:21  阅读:235  来源: 互联网

标签:codes return area text hw09 cs61a code 2021 input


网址 https://inst.eecs.berkeley.edu/~cs61a/fa21/hw/hw09/#q3-cs-classes
problem1:了解正则表达式规则就可以写了
problem2:
匹配[IVXLCDM],不能匹配出现在其他单词里面的用 \b,出现至少一次用+

        return re.findall(r"\b[IVXLCDM]\b+", text)

problem3:

        return bool(re.search(r'cs|CS ?\d+[(a|A)|(b|B)|(c|C)]{1}', post))

probelm4:

        return re.findall(r'([01]?\d|2[0-3]):[0-5][0-9](AM)?', text)

problem5:

        return re.findall(r'(?:\()?(\d{3})(?:\)?)(?: |-)?\d{3}(?: |-)?\d{4}\b', text)

    def most_common_code(text):
        """
        Takes in an input string which contains at least one phone number (and
        may contain more) and returns the most common area code among all phone
        numbers in the input. If there are multiple area codes with the same
        frequency, return the first one that appears in the input text.

        >>> most_common_code('(501) 333 3333')
        '501'
        >>> input_text = '''
        ... (123) 000 1234 and 12454, 098-123-0941, 123 451 0951 and 410-501-3021 has
        ... some phone numbers. '''
        >>> most_common_code(input_text)
        '123'
        """
        "*** YOUR CODE HERE ***"
        area_codes_list = area_codes(text)
        cnts = [area_codes_list.count(e) for e in area_codes_list]
        maxnum = cnts.index(max(cnts))
        return area_codes_list[maxnum]

标签:codes,return,area,text,hw09,cs61a,code,2021,input
来源: https://www.cnblogs.com/echoT/p/16194401.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有