zoukankan      html  css  js  c++  java
  • 字符串、文件操作,英文词频统计预处理

    1.字符串操作:

    1.1解析身份证号:生日、性别、出生地等。

    # -*- coding : utf-8 -*-
    IdCard=input('请你输入18位身份证号码')
    while(len(IdCard)!=18):
        print('你输入的身份证号码长度有误,请你重新输入')
        IdCard=input()
    if(len(IdCard)==18):
        print('你的身份证号码为'+IdCard)
    year=IdCard[6:10];
    month=IdCard[10:12];
    day=IdCard[12:14];
    print("你的出生年月日为:"+year+""+month+""+day+"");
    if int(IdCard[16])%2 ==0:
        print("你的性别为女");
    else:
        print("你的性别为男");

    1.2 凯撒密码编码与解码

    ksmm=input('请输入你要加密的英文单词:')
    str=''
    ksmm=ksmm.lower()
    for i in range(len(ksmm)):
        ksmm.split()
        if(ord(ksmm[i]) >=99 and ord(ksmm[i]) <=999):
            str=str + (chr(ord(ksmm[i])+7))
        else:
            str = str + ksmm[i]
    print(str)

    1.3网址观察与批量生成

    import  webbrowser as web
    url='http://news.gzcc.cn/html/xiaoyuanxinwen/'
    web.open_new_tab(url)
    for i in range(2,4):
        web.open_new_tab('http://news.gzcc.cn/html/xiaoyuanxinwen/'+str(i)+'.html')

          

    2.英文词频统计预处理

    • 下载一首英文的歌词或文章或小说,保存为utf8文件。
    • 从文件读出字符串。
    • 将所有大写转换为小写
    • 将所有其他做分隔符(,.?!)替换为空格
    • 分隔出一个一个的单词
    • 并统计单词出现的次数。
    f = open('C:\Users\unliee\Desktop\hello_1.txt','r',encoding='utf-8')
    text = f.read()
    print(text)
    print(text.split())
    print(text.count('big'),text.count('world'))
    f.close()

     

     

  • 相关阅读:
    SVN服务器搭建和使用(一)
    log4j.properties配置详解
    List<Map>来导出Excel数据
    JavaFX 表格数据显示简单Demo
    Java数组
    oracle数据 在已有的重复的数据上加联合唯一约束
    MyEclipse 9极速优化
    Eclipse中自定义Library
    Python 爬虫 1 (转)
    装修步骤 1
  • 原文地址:https://www.cnblogs.com/lb2016/p/10472100.html
Copyright © 2011-2022 走看看