博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python 自动化之 第5章 字符串在文本内容中的使用
阅读量:4144 次
发布时间:2019-05-25

本文共 3952 字,大约阅读时间需要 13 分钟。

1.将一段文章进行分割和替换判断例子如下

data ='''With the development of mechatronics engineering, bioengineering, ÑñÑñbiorobotics, and systems science, computer autonomous logical thinking will have enough behavior to be truly out of the control of humans, with an autonomous, intelligent mind. Big Data, brain computer interfaces and neural engineering will almost certainly 90% be the focus of breakthroughs by scientists in artificial intelligence and related fields in the next five to 10 years or more. Perhaps in the not-too-distant future, human-computer-assisted bioroids will indeed be able to fly as freely as iron man, operating "weapons" at will like a mech warrior, rewriting the course of life, traveling through time and space, and even existing outside of physical properties. In an era when the world was networked, bioroids, bioroids, and humans coexisted, Motoko Kusanagi, a Cyborg with a human brain and soul, was designed and created by Dr. Olette, joined the elite army of Public Security Section 9 to help the government fight high-tech crime... in addition to the ongoing Hollywood sci-fi blockbuster Ghost in the Shell, which tells the story of a Cyborg searching for its soul, the relationship between man and machine in the future is expounded. Human computer integration is seen as the next major turning point in artificial intelligence, and Ellon Elon Musk, an American technologist, is pushing for it. On March 28, Musk announced the creation of a company called neural connection, a technology company that aims to connect the human brain to a computer and improve its ability to deal with threats posed by artificial intelligence (AI) .'''

words = data.split()
redacted = [''.join('x' if w.isdigit() else w for w in word) for word in words]
ascii_text = [word.encode('ascii',errors = 'replace').decode('ascii') for word in redacted]
newlines = [word + '\n' if word.endswith('.') else word for word in ascii_text]
LINE_SIZE = 80
lines = []
line =''
for word in newlines:
    if line.endswith('\n') or len(line) + len(word) + 1 > LINE_SIZE:
        lines.append(line)
        line = ''
    line = line + ' ' + word
lines = [line.title() for line in lines]
result = '\n'.join(lines)
print(result)

 

 

注意1: 首先使用的split函数进行切片,使用x来取代进行替换并循环是否是整 数(0~10的数字),再将文本转换成ascii码,其中有西班牙语的字符替换成“?”。

最后是将单词组合成80个字符每行,将“。”号替换成“\n”换行符和定义行首 和行尾还有判断能否成为一行的条件。

2.输出结果如下

With The Development Of Mechatronics Engineering, Bioengineering,

 ????Biorobotics, And Systems Science, Computer Autonomous Logical Thinking Will

 Have Enough Behavior To Be Truly Out Of The Control Of Humans, With An

 Autonomous, Intelligent Mind.

 

 Big Data, Brain Computer Interfaces And Neural Engineering Will Almost

 Certainly Xx% Be The Focus Of Breakthroughs By Scientists In Artificial

 Intelligence And Related Fields In The Next Five To Xx Years Or More.

 

 Perhaps In The Not-Too-Distant Future, Human-Computer-Assisted Bioroids Will

 Indeed Be Able To Fly As Freely As Iron Man, Operating "Weapons" At Will Like A

 Mech Warrior, Rewriting The Course Of Life, Traveling Through Time And Space,

 And Even Existing Outside Of Physical Properties.

 

 In An Era When The World Was Networked, Bioroids, Bioroids, And Humans

 Coexisted, Motoko Kusanagi, A Cyborg With A Human Brain And Soul, Was Designed

 And Created By Dr.

 

 Olette, Joined The Elite Army Of Public Security Section X To Help The

 Government Fight High-Tech Crime...

 

 In Addition To The Ongoing Hollywood Sci-Fi Blockbuster Ghost In The Shell,

 Which Tells The Story Of A Cyborg Searching For Its Soul, The Relationship

 Between Man And Machine In The Future Is Expounded.

 

 Human Computer Integration Is Seen As The Next Major Turning Point In

 Artificial Intelligence, And Ellon Elon Musk, An American Technologist, Is

 Pushing For It.

 

 On March Xx, Musk Announced The Creation Of A Company Called Neural Connection,

 A Technology Company That Aims To Connect The Human Brain To A Computer And

 Improve Its Ability To Deal With Threats Posed By Artificial Intelligence (Ai)

转载地址:http://wcuti.baihongyu.com/

你可能感兴趣的文章
nginx反代 499 502 bad gateway 和timeout
查看>>
linux虚拟机安装tar.gz版jdk步骤详解
查看>>
python实现100以内自然数之和,偶数之和
查看>>
python数字逆序输出及多个print输出在同一行
查看>>
苏宁产品经理面经
查看>>
百度产品经理群面
查看>>
去哪儿一面+平安科技二面+hr面+贝贝一面+二面产品面经
查看>>
element ui 弹窗在IE11中关闭时闪现问题修复
查看>>
vue 遍历对象并动态绑定在下拉列表中
查看>>
Vue动态生成el-checkbox点击无法选中的解决方法
查看>>
MySQL Tricks1
查看>>
python 变量作用域问题(经典坑)
查看>>
pytorch
查看>>
pytorch(三)
查看>>
ubuntu相关
查看>>
C++ 调用json
查看>>
nano中设置脚本开机自启动
查看>>
动态库调动态库
查看>>
Kubernetes集群搭建之CNI-Flanneld部署篇
查看>>
k8s web终端连接工具
查看>>