This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Foo: | |
| count = 0 | |
| def __init__(self, a: int): | |
| self.a = a | |
| self.add1() | |
| @classmethod | |
| def add1(cls): | |
| cls.count += 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import functools | |
| from typing import List | |
| class Solution(object): | |
| def largest_nums(self, nums: List[int]) -> str: | |
| snums = [str(item) for item in nums] | |
| snums.sort(key=functools.cmp_to_key(self.cmp), reverse=True) | |
| _res = "" | |
| for i in snums: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| test_data = "1,2,3-7,9,13,15-19" | |
| def foo(some_array_string: str) -> list: | |
| res = [] | |
| items = some_array_string.split(',') | |
| for item in items: | |
| try: | |
| number = int(item) | |
| res.append(number) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| # build tree with python not class | |
| ref mowangdk | |
| https://blog.csdn.net/bell10027/article/details/51056114 | |
| users = tree() | |
| users['harold']['username'] = 'bell' | |
| users['handler']['username'] = 'master' | |
| print(json.dumps(users)) | |
| {'harold': {'username': 'bell'}, 'handler': {'username': 'master'}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| test_case = [2, 4, 6, 8, 0] | |
| def wine_sort(l): | |
| if l is []: | |
| return [] | |
| length = len(l) | |
| left = 0 | |
| right = length | |
| while left < right: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from flask import Flask | |
| from rq import Queue | |
| from rq.job import Job | |
| # ----- | |
| from redis import Redis | |
| from rq import Worker, Queue, Connection | |
| conn = Redis() | |
| # ----- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from ibm_watson import SpeechToTextV1 | |
| speech_to_text = SpeechToTextV1( | |
| iam_apikey='{apikey}'.format(apikey="APIKEY"), | |
| url='{url}'.format(url="https://stream.watsonplatform.net/speech-to-text/api") | |
| ) | |
| with open('audio-file.flac', 'rb')as audio_file: | |
| print(speech_to_text.recognize( | |
| audio_file, content_type='audio/flac', timestamps=True, model='zh-CN_NarrowbandModel', word_confidence=True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import datetime | |
| test_event = [ | |
| {"event": "try", "date": "2018 01-02 12:33:23", "amount": "3d"}, | |
| {"event": "buy", "date": "2018 04-02 12:33:23", "amount": "3m"}, | |
| {"event": "try", "date": "2018 05-02 12:33:23", "amount": "3d"}, | |
| {"event": "renew", "date": "2018 07-01 12:33:23", "amount": "1y"}, | |
| {"event": "renew", "date": "2018 10-01 12:33:23", "amount": "1m"}, | |
| {"event": "buy", "date": "2019 03-01 12:33:23", "amount": "1m"}, | |
| # {"event": "buy", "date": "2019 04-20 12:33:23", "amount": "0d"}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| # 将多个Excel文件合并成一个 | |
| import os | |
| import xlrd | |
| import xlsxwriter | |
| # 打开一个excel文件 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import heapq | |
| class TopK(object): | |
| def __init__(self, k): | |
| self.k = k | |
| self.heap = [] | |
| def push(self, elem): | |
| if len(self.heap) < self.k: |