my-python
文章平均质量分 72
Abalagang
这个作者很懒,什么都没留下…
展开
-
Xenia and Ringroad 的 python 实现
Xenia and RingroadDescriptionXenia lives in a city that has n houses built along the main ringroad. The ringroad houses are numbered 1 through n in the clockwise order. The ringroad traffic is one way and also is clockwise.Xenia has recently moved into原创 2021-04-26 23:41:02 · 155 阅读 · 0 评论 -
递归定义与递归相关问题的解决
递归定义与递归问题的解决1.递归定义对自身引用的东西的描述称为“递归”定义。所有良好的递归定义具有以下关键特征:有一个或多个基本情况,不需要递归。所有递归链最终都归结于其中一种基本情况。要确保满足这两个条件,最简单的方法是确保每个递归总是导致原来问题的 “较小” 版本。问题非常小的版本不用递归就可以解决,于是成为基本情况。这就是阶乘定义的工作方式。2.示例2.1 字符串反转虽然python的内置方法可以反转列表,可以将字符串转为字符列表,反转列表,并将列表重新转化为字符串,但是使用递归原创 2021-04-26 23:07:09 · 514 阅读 · 1 评论 -
A. Grammar Lessons的python代码实现
A. Grammar Lessons的python代码实现Petya got interested in grammar on his third year in school. He invented his own language called Petya’s. Petya wanted to create a maximally simple language that would be enough to chat with friends, that’s why all the languag原创 2021-04-16 16:57:56 · 203 阅读 · 0 评论 -
计算txt文档词频(字典操作)
计算txt文档词频(字典操作)# -*- coding: utf-8 -*-def wordcount(filepath): # 打开数据导入 text = open(filepath, "r", encoding="utf-8") words = [] line = text.readline() while line: words += line.split() # 将字符串分割为list,默认分隔符为空格 line = t原创 2021-04-16 00:24:48 · 347 阅读 · 0 评论