03 2018 档案
摘要:内容来自:python for information https://fanwscu.gitbooks.io/py4inf-zh-cn/chapter10.html 文本取自《罗密欧于朱丽叶》的第二幕第二场。现在,我们扩充这个程序,输出文本中出现次数最多的前十个单词,代码如下所示: 程序的第一部分
阅读全文
摘要:Python的split函数可以识别空格,把词汇看作是由空格分隔开来的词单元,所以,“soft”和“soft!”会被视为不同的词汇,分别为它们创建一个字典项。 由于文本中还存在大写,“who”和“Who”也是不同的词,分别进行统计。 通过字符串的lower、punctuation与translate
阅读全文
摘要:内容来自:python for information 将items方法、元组赋值与for循环结合起来,你可以拥有一个良好的代码模式,使用单循环就可以遍历字典中的键与值。 这个循环中存在两个迭代变量。由于items返回一个元组列表,变量key和val通过字典的键值对进行迭代,继而得到赋值。 循环中的
阅读全文
摘要:#9.4 Write a program to read through the mbox-short.txt and figure out who has the sent# the greatest number of mail messages. The program looks for '
阅读全文
摘要:8.4 Open the file romeo.txt and read it line by line. For each line, split the line into a list of words using the split() method. The program should
阅读全文
摘要:发现自己在尝试循环和try结合时出现了死循环,好可怕。 例子:将用户输入的数值进行统计
阅读全文
摘要:警告:别老是缩进没缩好,语句放不好,逻辑有待加强 ex:提示用户一直输入
阅读全文
摘要:(截图来自coursera密歇根大学python for data structure week3 ) line8:使用rstrip去除行之间空格 line9:打印出来开头是该字符串的行 line13:取小数点后的数 line14:取整准备计算 line15:这里刚开始的时候我将他单独抽出来一个循环
阅读全文
摘要:a = 'kdjflsjdflsnc,nkdooooooo' print(a.count('o') //自己傻了,哈哈 >>> count = 0>>> word = "dkfjlskdjfaaaaa">>> for letter in word: if letter == "a": count =
阅读全文
摘要:6.5 Write code using find() and string slicing (see section 6.10) to extract the number at the end of the line below. Convert the extracted value to a
阅读全文
浙公网安备 33010602011771号