鱼C论坛

 找回密码
 立即注册

【Python学习笔记】统计字符找出关键信息

已有 403 次阅读2016-12-21 16:38

def count_list():
    num = 0; alph = 0; space = 0; other = 0
    message = str()
    data1 = open(r'D:\fishc\string1.txt').readlines()
    lenth1 = len(data1)
    for i in range(lenth1):
        for j in data1[i]:
            asc = ord(j)
            if 47<asc<58: num += 1
            elif 64<asc<91 or \
                 96<asc<123: 
                alph += 1;
                message += chr(asc)
            elif asc == 32: space += 1
            else:other += 1
    print 'The string has',num,'number,',\
          alph,'letter,',space,'space and',other,'other letter.'
    print 'The message is',message

路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 立即注册

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-5 22:19

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

返回顶部