博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
数据组合 ;歌曲分词
阅读量:5364 次
发布时间:2019-06-15

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

数据组合 classmate=['niko','john','tracy','张三']  ##定义一个列表 print(classmate[2])  ##输出列表 print(len(classmate))  ##取长 print(max(classmate)) print(min(classmate)) print(classmate.index('john'))  ##索引john 在哪个位置 print(classmate.count('tracy'))  ##计数tracy 几个字符 classmate[1]='tracy'   ##将列表中的john 改为tracy print(classmate) classmate.sort()  ##没有返回值,改变列表本身 classmate.insert(1,'jack')  ##在1的位置插入jack print(classmate) classmate.append('adem')  ##再增加一个名字 print(classmate)   歌曲分词
songStr='''The snow glows white on the mountain tonight Not a footprint to be seen A kingdom of isolation And it looks like I'm the queen The wind is howling like this swirling storm inside Couldn't keep it in, heaven knows I've tried Don't let them in, don't let them see Be the good girl you always have to be Conceal, don't feel, don't let them know Well, now they know Let it go, let it go Can't hold it back anymore Let it go, let it go Turn away and slam the door I don't care what they're going to say Let the storm rage on The cold never bothered me anyway It's funny how some distance makes everything seem small And the fears that once controlled me can't get to me at all It's time to see what I can do To test the limits and break through No right, no wrong, no rules for me I'm free Let it go, let it go I am one with the wind and sky Let it go, let it go You'll never see me cry Here I stand and here I'll stay Let the storm rage on My power flurries through the air into the ground My soul is spiraling in frozen fractals all around And one thought crystallizes like an icy blast I'm never going back, the past is in the past Let it go, let it go And I'll rise like the break of dawn Let it go, let it go That perfect girl is gone Here I stand in the light of day Let the storm rage on The cold never bothered me anyway '''.lower()  ##将歌词中的大写改为小写 songStr=songStr.replace(',','')   ##将歌词的逗号用空格 songStr=songStr.split()##将歌词分隔出一个个单词 print(songStr) print(songStr.count('let')) for word in songStr:   ##遍历每个词出现的次数     print(songStr.count(word)) ##sep=''',.:?""''' ##for c in sep :   将所有的符号用空格代替    ## songStr=songStr.replace(c,'') type(songStr) song =set(songStr) print(song) songDict={} for da in song:     songDict[da]=songStr.count(da)     print(songDict,len(songDict))
结果:

 

补充:2018/10/15
girlset =set(songStr.split()) girldict ={} for i in girlset:     girldict[i]=songStr.count(i) for key in girldict:     print(key,girldict[key]) wcList =list(girldict.items()) print(wcList) 结果:

 

##(函数定义)

## def.takeSecond(elem): ##   return elem[20] ##wcList.sort(key=takeSecond,reverse=True) ##items.sort(key=lambda x:x[1],reverse=True)  //匿名函数 wcList.sort(lambda x:x[20],reverse=True) print(wclist) 结果:

 

 

转载于:https://www.cnblogs.com/huang201606050002/p/9753434.html

你可能感兴趣的文章
Web框架——XWAF的代码结构和运行机制(4)
查看>>
实验四
查看>>
电话面试总结
查看>>
datatable列操作
查看>>
关于ManualResetEvent的实例分析
查看>>
手机与基站通信
查看>>
bzoj1061: [Noi2008]志愿者招募
查看>>
java学习笔记3——异或
查看>>
UVa1628 UVaLive5847 Pizza Delivery
查看>>
在QMainWindow内直接添加Layout行不通
查看>>
J2EE (十) 简洁的JSTL、EL
查看>>
zigbee学习:示例程序SampleApp中通讯流程
查看>>
Innosetup 设置文件的相对路径
查看>>
Windows一键设置环境变量(以设置java环境变量为例)
查看>>
阿里云CentOS7.3服务器通过Docker安装Nginx
查看>>
django组件之cookie与session
查看>>
C# WinForm程序退出的方法
查看>>
iOS支付宝,微信,银联支付集成封装调用(下)
查看>>
jQuery链式语法演示
查看>>
JavaScript 的时间消耗
查看>>