代码 #!/usr/bin/env python # -*- coding: utf-8 -*- # author: a2htray # create date: 2023/3/5 """ PAT 乙级 1017 """ if __name__ == '__main__': a, b = map(int, input().split(' ')) print(a // b, a % b)
代码 #!/usr/bin/env python # -*- coding: utf-8 -*- # author: a2htray # create date: 2023/3/5 """ PAT 乙级 1016 """ def count(string, char): c = 0 for v in string: if v == char: c += 1 return c def pad(char, num): if num == 0: return '0' ret = '' while num != 0: ret += char num -= 1 return ret if __name__ == '__main__':...
代码 #!/usr/bin/env python # -*- coding: utf-8 -*- # author: a2htray # create date: 2023/3/4 """ PAT 乙级 1015 """ from functools import cmp_to_key def sort_students(student1, student2): total1 = sum(student1[1:]) total2 = sum(student2[1:]) if total1 != total2: return -1 if total1 > total2 else 1 elif student1[1] !=...
代码 #!/usr/bin/env python # -*- coding: utf-8 -*- # author: a2htray # create date: 2023/3/4 """ PAT 乙级 1014 """ week_dict = { 'A': 'MON', 'B': 'TUE', 'C': 'WED', 'D': 'THU', 'E': 'FRI', 'F': 'SAT', 'G': 'SUN', } hour_dict = { '0': '00', '1': '01', '2': '02', '3': '03', '4': '04', '5': '05', '6': '06', '7': '07', '8':...
代码 # basic_1002.py chinese_pinyins = [ 'ling', 'yi', 'er', 'san', 'si', 'wu', 'liu', 'qi', 'ba', 'jiu', ] if __name__ == '__main__': num_chars = input() total = 0 for num_char in num_chars: total += int(num_char) output = [] for num_char in str(total): output.append(chinese_pinyins[int(num_char)]) print('...
代码 # basic_1001.py if __name__ == '__main__': n = int(input()) step = 0 while n != 1: if n % 2 == 0: n = n // 2 else: n = (3 * n + 1) // 2 step += 1 print(step) 运行 input: 100 output: 18
哈希表(hash)是 Redis 中重要的数据结构,本文通过示例演示如何使用 Python 完成对哈希表的操作,各方法调用分别对应着 Redis 的一个指令:
- HSET
- HGET
- HINCRBY
- HINCRBYFLOAT
- HSTRLEN
- HVALS
- HMSET
- HMGET
- HSETNX
Redis 服务器中与哈希表相关的命令。
zset 有序集合是 set 的补充,zset 中的元素都带有一个用于排序的分数,以下通过代码示例进行说明。