Case study: word play

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,布布扣,bubuko.com

时间: 2024-10-13 10:55:44

Case study: word play的相关文章

【转】 Android Performance Case Study(安卓绘图性能案例研究)

注:这篇文章是Google员工Roman Guy在其博客上发表的,主要研究了影响安卓绘图性能的一些原因,并讲解了怎样使用Android自带的测试工具来验证性能. Android Performance Case Study by Romain Guywww.curious-creature.org Falcon Pro I recently installed Falcon Pro, a new Twitter client, on my Nexus 4. I really enjoy usin

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

关于故障的事后复盘,英文名 Case Study是非常有必要做的,当然是根据故障的级别,不可能做到每个故障都Case Study,除非人员和时间充足: 文档能力也是能力的一种,一般工程师的文档能力比较薄弱或者一般 ,但是一般各种类型的文档其实都有模板,根据模板填充内容也能事半功倍. 故障要有记录, 每个公司应当都有wiki,这些复盘应当记录下来,能学习到很多.Case Study会占用大量的时间, 但是中级以及重大故障还是有必要的. 下面介绍的就是复盘的整体套路: 故障描述 xxx业务状态码报警

吴恩达《深度学习》-课后测验-第三门课 结构化机器学习项目(Structuring Machine Learning Projects)-Week2 Autonomous driving (case study) (case study)( 自动驾驶 (案例研究))

Week2 Autonomous driving (case study) (case study)( 自动驾驶 (案例研究)) \1. To help you practice strategies for machine learning, in this week we'll present another scenario and ask how you would act. We think this "simulator" of working in a machine l

Case study: 用R统计分析医院疾病相关数据

The data come from the Hospital Compare web site (http://hospitalcompare.hhs.gov)run by the U.S. Department of Health and Human Services. The purpose of the web site is to provide data andinformation about the quality of care at over 4,000 Medicare-c

【论文阅读-CTR】<<Deep Learning over Multi-filed Categorical Data -A Case Study On User Response Prediction>>阅读

摘要: 用户反馈预估是搜素.推荐.广告的核心问题:其特征都是多域的分类和数值特征,难以利用: 常用的方法是线性模型+人工特征组合来预估: 本文通过FNN(基于FM)和SNN(基于RBM和DAE)来预估. 1.介绍 常用的ctr预估模型: 1)线性模型:LR->NB->FTRLLR->Bayesian probit regression 优点:容易实现:高效学习 缺点:不能学习特征组合,效果较差 2)非线性模型:FM,GBM 优点:自动学习组合特征 缺点:不能充分利用各种特征组合 很多模型

LAB - CCNP BGP Case Study

Topology Objectives: Plan, design, and implement the internation Travel Agency core network. Plan, design, nad implement the Travel Data Providers netwrok. Allow the networks to communicate via BGP. Verify that all implementations are operational and

LAB - OSPF Case Study

Topology Requirements: 1. Use the addressing scheme shown in the diagram.2. Configure OSPF with the networks shown in the diagram.3. Configure the OSPF backbone area to be on Loopback0 on HQ.4. Configure the Frame Relay subnets as point-to-point subi

To discount or not to discount in reinforcement learning: A case study comparing R learning and Q learning

https://www.cs.cmu.edu/afs/cs/project/jair/pub/volume4/kaelbling96a-html/node26.html [平均-打折奖励] Schwartz [106] examined the problem of adapting Q-learning to an average-reward framework. Although his R-learning algorithm seems to exhibit convergence p

journal / case study网站推荐

ScienceDirect.com | Science, health and medical journals https://www.sciencedirect.com 电气电子工程师学会网站 http://ieeexplore.ieee.org 计算机协会官方网站 https://www.acm.org/ 原文地址:https://www.cnblogs.com/whisper-yyf/p/8642614.html