• 替换敏感字符,统计,乘法表,函数


    #!/usr/bin/env python
    # -*- coding:utf-8 -*-

    # 1.替换敏感字符
    # keys = ['苍老师', '小泽老师', 'alex']
    # with open('file.txt', mode='r', encoding='utf-8') as f1, open('2.txt', mode='w', encoding='utf-8') as f2:
    # for line in f1:
    # for a in keys:
    # if a in line:
    # line = line.replace(a, '***')
    # f2.write(line)

    # 2.统计各省车牌数
    # cars = ['鲁A3244','鲁B12333','京B8989M','黑C49678','黑C46555','沪B25041','黑C34567']
    # dic = {}
    # for i in cars:
    # a = i[0]
    # if a in list(dic.keys()):
    # dic[a] += 1
    # else:
    # dic[a] = 1
    # print(dic)

    # 3.数据添加到字典.
    # info = []
    # with open('data.txt',mode='r',encoding='utf-8') as f1:
    # a = f1.readline()
    # for lines in f1:
    # dic = {}
    # i = lines.split(',')
    # count = 0
    # for k in a.split(','):
    # dic[k.strip()] = i[count].strip()
    # count += 1
    # info.append(dic)
    # print(info)

    # 4.小九九乘法表
    # for a in range(1,10):
    # for b in range(1,a+1):
    # if a == b:
    # print(str(a) + '*' + str(b))
    # else:
    # print(str(a)+'*'+str(b),end=' ')

    # 5.读取文件,将文件的内容构造成指定格式的数据,并返回。
    # """
    # a.log文件
    # alex|123|18
    # eric|uiuf|19
    # ...
    # 目标结构:
    # a. ["alex|123|18","eric|uiuf|19"] 并返回。
    # b. [['alex','123','18'],['eric','uiuf','19']]
    # c. [
    # {'name':'alex','pwd':'123','age':'18'},
    # {'name':'eric','pwd':'uiuf','age':'19'},
    # ]

    '''
    def func1():
    lst = []
    with open('a.log', mode='r', encoding='utf-8') as f:
    for line in f:
    lst.append(line.strip())
    return lst

    print(func1())
    '''

    '''
    def func2():
    lst = []
    with open('a.log', mode='r', encoding='utf-8') as f:
    for line in f:
    a = line.strip().split('|')
    lst.append(a)
    return lst
    '''

    '''
    def func3():
    lst = []
    with open('a.log', mode='r', encoding='utf-8') as f:
    for line in f:
    dic = {}
    a, b, c = line.strip().split('|')
    dic['name'] = a
    dic['pwd'] = b
    dic['age'] = c
    lst.append(dic)
    return lst
    print(func3())
    '''


    # 6.不用max和min找出最大最小值.
    '''
    def func(*args):
    ma = args[0]
    mi = args[0]
    for i in args:
    if i > ma:
    ma = i
    if i < mi:
    mi = i
    return {'最大值':ma,'最小值':mi}
    print(func(1,6,8,7,1,2,4))
    '''

    # 传入n,返回n的阶乘.
    '''
    def func(n):
    res = 1
    for i in range(1, n+1):
    res *= i
    return res

    print(func(7))
    '''






  • 相关阅读:
    富可视M310刷机包 MIUIV5 红米开发版 闪光 美化 稳定
    Windowsclient SSH 远程连接Windowsserver(PowerShell Server)
    数据结构与算法02--链表基础
    rhadoop linear regression 问题
    奇怪的git代理超时问题
    怎样利用Heartbeat与Floating IP在Ubuntu 14.04上创建高可用性设置
    IVS_原理
    NN入门
    算法体系
    CNN原理
  • 原文地址:https://www.cnblogs.com/zjx1/p/10676469.html
Copyright © 2020-2023  润新知