python Rise Hackathon第4周挑战赛

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Rise Hackathon第4周挑战赛相关的知识,希望对你有一定的参考价值。

# Author : Louis Christopher
# LICENSE : https://goo.gl/48c5PX
#
#
#
# Program to sort a string delimited by any character
# Advantage:
# - Highly portable, tested on Python 2.7 and 3.5
# - Highly customizable and easy to use.
#   Instantiate the class with your own defaults
#
# Example:
#
#    fixlist = sortByTokens(False, ',')
#    print( fixlist( 'B , b , a , A' ) )
#
#    ['A', 'B', 'a', 'b']


class sortByTokens():
    """
    ReturnType : List

    sortByTokens class takes two arguments during instantiation

    ignoreCase, set to True by default
    delimter, set to '>' by default. Must be a single character

    Usage : sortByTokens()(<string>)

    """

    def __init__(self, ignoreCase=True, delimiter='>'):
        if type(ignoreCase) is bool:
            self.ignoreCase = ignoreCase
        else:
            raise ValueError('ignoreCase must be a Boolean')
        if len(delimiter) == 1:
            self.delimiter = delimiter
        else:
            raise ValueError('delimiter must be a single character')

    def __call__(self, inputString):
        tokens = inputString.split(self.delimiter)
        tokens = [x.lower().strip() if self.ignoreCase else x.strip()
                  for x in tokens]
        uniqueTokens = set(tokens)
        return sorted(uniqueTokens)


fix = sortByTokens()

print(fix('a > b > c > d > c > e > f > b'))
print(fix('vivek > sid > vignesh > nik > smriti > vivek > prateek > nik'))

print(fix('B > b > a > A'))

fixlist = sortByTokens(False, ',')

print(fixlist('B , b , a , A'))

以上是关于python Rise Hackathon第4周挑战赛的主要内容,如果未能解决你的问题,请参考以下文章

参加过 4 届 TiDB Hackathon 是一种什么体验? | TiDB Hackathon 选手访谈

让迁移不再开盲盒,让云也能省钱丨Hackathon 项目背后的故事第一期回顾

Vulnhub_Hackathon2

Vulnhub_Hackathon2

释放你的创造力,来MongoDB Hackathon与黑客大佬巅峰对决

[TechM Event](Bay Area) Apache Kafka: The Rise of Real-time