For the exercises in this chapter we need a list of English words. There are lots of word lists available on the Web, but the most suitable for our purpose is one of the word lists collected (and contributed to the public domain) by Grady Ward as part of Moby lexicon project. It is a list of 113,809 official crosswords; that is, words that are considered valid in crossword puzzles and other word games. In the Moby collection, the filename is 113809of.fic; if you download the swampy, there is a copy of this file, with the simpler name words.txt. this file is in plain text, so you can open it with a text editor, but you can also read it from Python. The built-in function open takes the name of the file as a parameter and returns a file object you can use to read the file. The file object provides several methods for reading, including readline, which reads characters from the file until it gets to a newline, and returns the result as a string. Note that you need to put the file in your work directory. Or you can change your work directory:

Exercises

1. Write a program that reads words.txt and prints only the words with more than 20 characters.

2. Write a function called has_no_e to print the words that have no ‘e’ and compute the percentage of the words in the list have no ‘e’.

……….

Simple way to verify your result:

3. Write a function named avoids that takes a string of forbidden letters. Print the number of words that don’t contain any of them.

4. Write a function named uses_only that takes a word and a string of letters, and that returns the word if it contains only letters in the list.

5. Write a function named uses_all that takes a string of required letters, and that returns the word uses all the required letters at least once.

6. Write a function named uses_all_only that takes a string of required letters, and that returns the word uses all the required letters at least once and only contains the list of the letters.

7. Write a function called is_abecedarian that returns the word if the letters in a word appear in alphabetical order (exclude double letters). And also print how many abecedarian words are there.

……..

8. A palindrome is a word that reads the same forward and backward, like ‘rotator’ and ‘noon’. Write a function print all the palindrome words and the print the number as well.

……

from Thinking in Python

Case study: word play的更多相关文章

  1. Data Visualization – Banking Case Study Example (Part 1-6)

    python信用评分卡(附代码,博主录制) https://study.163.com/course/introduction.htm?courseId=1005214003&utm_camp ...

  2. 【ASE模型组】Hint::neural 模型与case study

    模型 基于搜索的提示系统 我们的系统用Pycee针对语法错误给出提示.然而,对于语法正确.结果错误的代码,我们需要另外的解决方式.因此,我们维护一些 (错误代码, 相应提示) 的数据,该数据可以由我们 ...

  3. Case Study: Random Number Generation(翻译教材)

    很荣幸,经过三天的努力.终于把自己翻译的教材做完了,现在把它贴出来,希望能指出其中的不足.   Case Study: Random Number Generation Fig. 6.7  C++ 标 ...

  4. 课程三(Structuring Machine Learning Projects),第一周(ML strategy(1)) —— 1.Machine learning Flight simulator:Bird recognition in the city of Peacetopia (case study)

    []To help you practice strategies for machine learning, the following exercise will present an in-de ...

  5. Attacking JavaScript Engines: A case study of JavaScriptCore and CVE-2016-4622(转)

    转:http://phrack.org/papers/attacking_javascript_engines.html Title : Attacking JavaScript Engines: A ...

  6. 关于运维之故障复盘篇-Case Study

    关于故障的事后复盘,英文名 Case Study是非常有必要做的,当然是根据故障的级别,不可能做到每个故障都Case Study,除非人员和时间充足: 文档能力也是能力的一种,一般工程师的文档能力比较 ...

  7. 李宏毅机器学习课程---2、Regression - Case Study

    李宏毅机器学习课程---2.Regression - Case Study 一.总结 一句话总结: 分类讨论可能是比较好的找最佳函数的方法:如果 有这样的因素存在的话 模型不够好,可能是因素没有找全 ...

  8. 你从未见过的Case Study写作指南

    Case Study,意为案例分析,Case Study与其它的留学论文作业最大的的差别就在于Case Study在论文开始就需要明确给出论,然后再阐述这个结论的论证依据和理由.留学生们需要知道的是C ...

  9. Deep Learning-Based Video Coding: A Review and A Case Study

    郑重声明:原文参见标题,如有侵权,请联系作者,将会撤销发布! 1.Abstract: 本文主要介绍的是2015年以来关于深度图像/视频编码的代表性工作,主要可以分为两类:深度编码方案以及基于传统编码方 ...

随机推荐

  1. C++ OTL MySQL(Windows/Linux) V8.1

    Windows每秒钟10000条以上插入:Linux每秒插入300条以上.Q269752451 输出截图: Linux输出: Windows输出: 有须要的联系 QQ 3508551694 water ...

  2. inputstream输出为String

    import java.io.IOException; import java.io.InputStream; import org.apache.http.HttpEntity; import or ...

  3. hihocoder 1407 重复旋律2

    思路: 二分一哈答案 height分个块 //By SiriusRen #include <cstdio> #include <cstring> #include <al ...

  4. Kafka Consumer2

    本文记录了和conumser相关的几个类. 首先是RequestFuture这个类,consumer和服务端通信使用它作为返回值. 其次是HeartBeat机制,consumer和coordinato ...

  5. Swift学习笔记(6):控制流

    目录: For-In While If-Else, Guard-Else Switch 控制转移 For-In 可以使用for-in语句循环遍历集合.区间.元组.字符串. // 遍历区间,返回元素值 ...

  6. 3DES(或称为Triple DES)是三重数据加密算法(TDEA,Triple Data Encryption Algorithm)

    3DES(或称为Triple DES)是三重数据加密算法(TDEA,Triple Data Encryption Algorithm)块密码的通称.它相当于是对每个数据块应用三次DES加密算法.由于计 ...

  7. POJ 2739 Sum of Consecutive Prime Numbers【素数打表】

    解题思路:给定一个数,判定它由几个连续的素数构成,输出这样的种数 用的筛法素数打表 Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memo ...

  8. SpringCloud学习笔记(1)----认识微服务与SpringCloud

    1.  微服务是什么? 微服务是一种由多个服务组成的集合体,它属于一种软甲架构,在微服务中,它的每个服务都是独立存在的,微服务是一种去中心化的思想. 它具有开发简单,技术栈灵活,服务独立解耦,可用性高 ...

  9. Vue this.$router.push、replace、go的区别

    1.this.$router.push 描述:跳转到不同的url,但这个方法会向history添加一个记录,点击后会返回到上一个页面 用法 //字符串 this.$router.push('home' ...

  10. WordPress 增加 keywords 和 description

    WordPress 增加 keywords 和 description . <?php $keywords = '798资源网'; $description = '798资源网'; //文章页 ...