Exercise: Week 2-7
时间:2019-11-20
本文章向大家介绍Exercise: Week 2-7,主要包括Exercise: Week 2-7使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
File artical.txt contains an article in English (please create the file by yourself and put any English article you picked in it).
Assume the article only contains ‘,’, ‘.’, ‘!’, ‘?’ and ‘...’ as punctuations, make a program to find out the longest word and print it.
artical.txt
Last week, thousands of student protesters streamed into Hong Kong Polytechnic University and occupied the campus as the city's violent political unrest reached fever pitch.
Once inside, they soon faced an impossible choice: stay inside until supplies run out, or leave the university and risk getting tear gassed and arrested for rioting, a charge which can fetch a 10-year prison sentence.
Police accused protesters of turning PolyU and other universities into "weapons factories" that "look like military training grounds" and surrounded the campus.
Police have been on the edge of the campus for more than two days, firing round after round of tear gas at protesters who responded with makeshift petrol bombs, catapults and bows and arrows.
with open('artical.txt', 'r') as f:
text = f.read()
text = text.replace('\n', ' ')
l = text.split(' ')
str = ''
for item in l:
for c in item:
if c.isalpha() != True:
item = item.replace(c, '')
if len(item) > len(str):
str = item
print(l)
print(str)
2019-11-20
16:50:16
原文地址:https://www.cnblogs.com/petitherisson/p/11896789.html
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法