
编程练习与算法设计
文章平均质量分 65
ML_R
厚德,博学,笃行,创新,信义仁爱,思学志远
展开
-
6.算法编程练习:词频统计(1)
文章目录1. 题目2. 分析3. 代码4. 小结致谢1. 题目从data.txt文件读入一篇文章《从清华到MIT》,用 jieba 库的函数 lcut 的全模式做分词,统计词汇长度为 2 的词出现的次数,输出出现次数最多的前 10 个词汇及其出现次数。2. 分析读入,分词,定义一个字典存次长为2的词并将出现的频数统计为字典的关键字值,然后排序原创 2021-10-22 07:58:36 · 877 阅读 · 0 评论 -
5. 算法编程练习:Find the unique number
Find the unique numberInstructionsThere is an array with some numbers. All numbers are equal except for one. Try to find it!find_uniq([ 1, 1, 1, 2, 1, 1 ]) == 2find_uniq([ 0, 0, 0.55, 0, 0 ]) == 0.55Sample Teststry:import codewars_test as testexce原创 2021-08-19 19:13:10 · 188 阅读 · 0 评论 -
4. 算法编程练习:Highest Scoring Word
Highest Scoring WordGiven a string of words, you need to find the highest scoring word.Each letter of a word scores points according to its position in the alphabet: a = 1, b = 2, c = 3 etc.You need to return the highest scoring word as a string.If two原创 2021-08-14 20:44:36 · 270 阅读 · 0 评论 -
3. 算法编程练习:Find the odd int
Find the odd intGiven an array of integers, find the one that appears an odd number of times.There will always be only one integer that appears an odd number of times.Exampletest.assert_equals(find_it([20,1,-1,2,-2,3,3,5,5,1,2,4,20,4,-1,-2,5]), 5)test原创 2021-08-11 00:10:37 · 362 阅读 · 0 评论 -
2. 算法编程练习:Give me a Diamond
Give me a DiamondJamie is a programmer, and James’ girlfriend. She likes diamonds, and wants a diamond string from James. Since James doesn’t know how to make this happen, he needs your help.TaskYou need to return a string that looks like a diamond shap原创 2021-08-09 17:20:35 · 242 阅读 · 0 评论 -
1. 算法编程练习:persistence(39) # returns 3, because 3*9=27, 2*7=14, 1*4=4 # and 4 has only one dig
ContentsProblem description:For example:Code:ConcludingProblem description:Write a function, persistence, that takes in a positive parameter num and returns its multiplicative persistence, which is the number of times you must multiply the digits in num原创 2021-08-08 12:16:32 · 182 阅读 · 0 评论