专栏首页python3python练习记录

python练习记录

# -*- coding: utf-8 -*-
import random,fileinput,calendar
import string,datetime
import time
import re,os,sys

class Monday():
    # 现在日期
    now = datetime.datetime.now()
    NowYear = now.year
    LastYear = now.year - 1
    NextYear = now.year + 1
    def __init__(self,number):
        self.number = number

    def print_01(self):
        print '''1、 打印 %d 开始到3000之间被7整除但不被5整除的数,以, (逗号)分隔:'''%self.number
        for i in range(self.number,3000):
            if i % 7 == 0 and i % 5 != 0:
                print i,

    def print_02(self):
        print '\n'
        print "统计一个字符串中每一个字母一共累计出现的次数"
        s = "aaabbbcccddeeffAAABBBDDEE"
        s_dic = {}
        for i in s:
            if s_dic.has_key(i):
                s_dic[i] += 1
            else:
                s_dic[i] = 1

        print s_dic,'\n'

    def print_03(self):
        print '# 2个长度相同的list,一个里面的做字典的key,另一个做value,请写个函数实现'
        a = [1, "2", [3, 4], (5, 6), {7: 8}]
        b = [0, 1, 2, 3]
        d_dic = {}
        for i in range(len(a)):
            if not isinstance(a[i],(int,float,long,complex,unicode,tuple)):
                continue
            else:
                d_dic[a[i]] = b[i]
        print d_dic

    def print_04(self):
        print '\n'
        print "有一个长度是101的数组,存在1~100的数字,有一个是重复的,找出重复的找出来"
        a_len = range(1,101)
        number = random.randint(0,99)
        print "随机生存的随机数是:%d."%number
        a_len.insert(number,number)
        for i in a_len:
            if a_len.count(i) == 2:
                #print i
                print '''找到的随机数是:%d'''%i,'\n'
        print "一句代码打印:",[i for i in a_len if a_len.count(i) == 2][0],'\n'

    def print_05(self,a):
        print'''求长度最长的单词和索引:'''
        a_list = a.split()

        # print a_list
        # len_dic = {}
        # for i in range(len(a_list)):
        #     len_dic[a_list[i]] = len(a_list[i])
        # print len_dic

        print "最长的单词是:",a_list[len(a_list) -1],'\nindex:',a_list.index(a_list[len(a_list) -1])
        a_lenth = map(len,a_list)

    def pass_06(self):
        print '\n'
        print "打印10位大小数字密码:"
        pwordstring = []
        for i in range(3):
            pwordstring.append(random.choice(string.lowercase))
        for i in range(3):
            pwordstring.append(random.choice(string.uppercase))
        for i in range(4):
            pwordstring.append(random.choice(string.digits))
        random.shuffle(pwordstring)

        return "".join(pwordstring)
    def print_07(self):
        print '\n去重复第一种:'
        a = [1,2,1,2,2,3,4,4,5,5,6,6,6,6]
        res = []
        for i in a:
            if i not in res:
                res.append(i)
        print res
        print '\n去重复第二种:'
        print set(a)
        print '\n去重复第三种:'
        qcdic = {}
        print list(qcdic.fromkeys(a))

    def print_08(self,list_itme):
        for list_value in list_itme:
            if isinstance(list_value,list):
                self.print_08(list_value)
            else:
                print list_value

    def print_09(self):
        n = []
        print "输入3个数字,以逗号隔开,输出其中最大的数"
        num = (raw_input('three number eter:\n')).split(',')
        n.append(num[0])
        n.append(num[1])
        n.append(num[2])

        print "最大值是:",max(n)

    def print_10(self):
        try:
            print "请输入3个单词每个单词逗号隔开:"
            a = []
            for i in range(3):
                num = raw_input()
                a.append(num)
            return ",".join(a)
        except:
             print "soory!"

    def print_11(self):
        print"猜字谜:"
        num = random.randint(0,100)
        #print num
        ncount = 0
        while True:
            ncount += 1
            input_num = input("please input number:")
            if input_num == num:
                print "恭喜你猜对的了"
                print "一共猜了%d次"%ncount
                break
            if input_num > num :
                print '你输入大了'
            else:
                print '您输入小了'
    def print_12(self):
        print '生成一个1到50的大字符串每个数字之间有空格'
        res = ""
        for i in range(50):
            if i == 50:
                res = res + str(i)
            else:
                res += str(i) + " "
        print res

    def print_13(self):
        print "使用while统计的句子中有几个数字,动态输入\n"
        conten = raw_input("please input content:")
        res = 0
        i = 0
        while i < len(conten):
            if conten[i] in '1234567890':
                res += 1
            i += 1
        print res

    def print_14(self):
        print'将一个列表元素倒序存在一个新列表中'
        a = [1,2,3,4,5,6,7,8]
        a_1 = a[::-1]
        print 'firs'
        print a_1
        print 'two:'
        a_new = []
        for i in a:
            a_new.insert(0,i)
        print a_new
        print "大写字母链接成字符串:"
        print string.uppercase
        print "小写字母链接成字符串:"
        print string.lowercase
        print "一大写一小写字母输出"
        daxiao = ""
        for s in range(65,65+26):
            daxiao += chr(s) + chr(s + 32)

        print daxiao
    def print_15(self):
        even = []
        odd = []
        a = [4,36,24,3,53]
        for i in a:
            if i %2 == 0:
                even.append(i)
            else:
                odd.append(i)
        print even,'\n'
        print odd,'\n'
        print "查找一个句子中有多少个a字母"
        s = "i am a booy"
        ncount = 0
        print "a = ",s.count("a")
        for i in s:
            if i in "a":
                ncount += 1
        print 'a:',ncount
    def print_16(self):
        a = [1, 2, 3, 4, 5, (1, 2), (5, 6)]
        for i in a:
            if isinstance(i,(list,tuple)):
                print i
            else:
                print i
    def print_17(self):
        print "统计名字列表中,各名字的首字母在名字列表中出现的次数"
        name_list = ['fosjkter', "jandet", 'kessfduks', 'david']
        count_dic = {}
        for i in name_list:
            count_dic[i] = "".join(name_list).count(i[0])
        print count_dic
        print "一个list 包含10个数字,然后生成新的List,要求,新的list里面的数都比之前的数多1"
        n = range(10)
        n_new = []
        for i in range(len(n)):
            n_new.append(i + 1)
        print n_new
    def print_18(self,s):
        print "写一个而函数,一个字符串作为参数,函数需要将此字符串的偶数位字母做一个返回"
        re = []
        for i in range(len(s)):
            if i % 2 == 0:
                re.append(s[i])
        return "".join(re)

    def print_19(self,*args):
        print "使用可变参数的形式,将所有参数相乘,并将结果作为函数的返回值"
        res = 1
        for i in args:
            res *= i
        return res
    def print_20(self,n):
        print "读入一组数字,然后把每个数字加一后输出。比如说:123,输出之后是2、3、4"
        #a = [1,3,4]

        res = []
        for i in n:
            res.append(i)
        print res
        res1 = []
        for i in res:
            res1.append(str(int(i) + 1))
        print int("".join(res1))

    def print_21(self):
        print "计算一个浮点相乘记录时间,并且还回时间"
        start_time = time.time()
        i = 0.22
        for i in range(100000):
           print i * i

        end_time = time.time()

        print 'time:%d'%(time.time() - start_time)

    '''使用map函数,将一个字符串中的小写字母删除掉,例如:“AABBaabb”,结果返回\"AABBdd'''
    def print_22(self,s):

        if s >= 'a' and s <= "z":
            return ""
        else:
            return s

    def tongji(self):
        a = "aabbaabbccddee"
        d = {}
        for i in a:
            d[i] = a.count(i)
        print d

        c = {}
        for i in a:
            if c.has_key(i):
                c[i] += 1
            else:
                c[i] = 1
        print c
        print "*"*10
        '''a=[1,2,3,4,5,6]'''
        a1=[1,2,3,4,5,6]
        dd = {}
        for i in range(0,(len(a1) - 1),2):
            dd[a1[i]] = a1[i + 1]
        print dd

        '''练习统计每个单词的个数'''
        s1 = "I am a boy a good boy a bad boy"
        s_dic = {}
        sc = s1.split()
        print sc
        for i in sc:
            s_dic[i] = sc.count(i)

        print s_dic

        print "*"*10

        ss = "lwer wrwre reet etr"
        rs = []
        for i in range(len(ss)):
            if i % 2 == 0:
                rs.append(i)
        print "".join(ss.split()[::-1])
        res = ""
        for i in range(3):
            res += str(i) + "*"
        print res
        '''计算单词最长'''
        sentence = "I am a boy haa"
        new_set = sentence.split()
        d = {}

        for i in range(len(new_set)):
            d[new_set[i]] = len(new_set[i])
        print "d{}:",d
        #print d
        new_set = sentence.split()
        print new_set
        for i in new_set:
            print len(i),

        print "==========="
        a = {'a':1,'b':2}
        tem = ''
        for k,v in a.items():
            tem = k
            k = v
            v = tem
            print k ,":",v

        ls = [1, 2, 3, 4, 5, 6, 7, 8]
        s = {}
        for i in range(0,(len(ls) - 1),2):
            s[ls[i]] = ls[i + 1]
        print s

        print 'ood',ls[::2]
        print 'even',ls[1::2]
    def max_01(self):
        print '''从键盘输入两个数,并比较其大小,直到输入e/E退出程序'''
        try:
            while True:
                num = raw_input("two number,','")
                num1 = num.split(',')[0]
                num2 = num.split(',')[1]
                if num1.lower() == 'e' and num2.lower() == 'e':
                    print "程序退出!"
                    return
                if num1 >num2:
                    print 'max', num1
                    continue
                else:
                    print 'max:',num2
                    continue
        except:
            print "输入有问题!!无法比较,程序退出"

    def mvbs(self):
        s = "I am a good boy,ages 8 years old,and i like 76team!"
        res = ""
        for i in s:
            if i in string.digits:
                continue
            elif i in string.punctuation:
                continue
            else:
                res += i
        print res

        word_list = "a apple business da"
        print word_list.count("a")

        word_list = "a apple business da".split()
        count = 0
        for i in word_list:
            if "a" in i:
                count += 1
        print count

        '''数据5.统计各个单词的首字母在列表中出现的次数'''
        s = ['wab', 'a', 'fawwa', 'good', 'boy?']

        resa = {}
        s1 = []
        for i in s:
            s1.append(i)

        for j in s1:
            resa[j] = s1.count(i)
        print resa
        for i in s:
           resa[i] = "".join(s).count(i[0])
        print resa

        s = "aaabbbcccddeaaeffAAABBBDDEE"
        ss = {}
        for i in range(len(s) - 1):
            ss[s[i]] = s.count(s[i])
        print "sssss:",ss
        print "*"*10
        re = ""
        swe = "dddd2323,34,45ewdww,3o"
        for i in swe:
            if i in string.digits:
                continue
            elif i in string.punctuation:
                continue
            else:
                re += i
        print re

        d = ['a', 'apple', 'business', 'da']
        ii = 0
        for i in d:
            if 'a' in i:
                ii += 1
        print ii

    def ss01(self,x):
        for i in x:
            if i not in string.letters:
                return False
            else:
                return True
        return True
        # 15、实现字符串的join方法
    def myjion(self,s,fs):
        ns = ""
        if not isinstance(s,(basestring,list,tuple,dict)):
            raise TypeError
        if len(s) == 0:
            return s
        for i in s:
            ns += i + fs
        return ns[0:len(ns) - 1]
    def print_re(self):
        s = '''111aa bb 11 aaaaa'''
        res = re.findall(r'[A-Za-z] + |\d+',s)
        print map(lambda x : x[0],res)

    def file_os(self):
        print "当前路径:"
        print os.getcwd()
        print "判断是否是一个文件:"
        print os.path.isfile(os.getcwd())
        print "是否是一个目录:"
        print os.path.isdir(os.getcwd())
        print os.system("ls")
        print "判断是否是绝对路径:"
        print os.path.isabs("excp01.py")
        print "检验给出的路径是否真地存:"
        print os.path.exists("/Users/zhouhaijun")
        print "返回一个路径的目录名和文件名"
        print os.path.split("/Users/zhouhaijun")
        print "分离文件名与扩展名"
        print os.path.splitext("tmp1.dat")
        print "找出某个目录下所有的文件,并在每个文件中写入“osTest”"
        for root,dis,files in os.walk("/Users/zhouhaijun/Desktop/hhhhh/osTest"):
            for name in files:
                print name,root,os.path.join(root,name)
                with open(os.path.join(root,name),"w") as fp:
                    fp.write("good! liwen \n 学习walk"
                             "命令")
        print "ok!"

        print "如果某个目录下文件名包含dat后缀名,则把文件后面追加写一行“被我找到了!"
        for root,dirs,files in os.walk("/Users/zhouhaijun/Desktop/hhhhh/osTest"):
            for name in files:
                suffix = os.path.splitext(os.path.join(root,name))[-1]
                if suffix in "dat":
                    print name
                    with open(os.path.join(root,name),"a") as fp:
                        fp.write("\n我找到了!!!")
        print "修改内容:"
        os.system("cd /Users/zhouhaijun/Desktop/hhhhh/osTest")
        print "获取当前路径"
        os.chdir("/Users/zhouhaijun/Desktop/hhhhh/osTest")
        print "获取当前目录:"
        print os.getcwd()
        for line in fileinput.input("dd",inplace = 1):
            line = line.replace("walk","\n复习fileinput.input命令")
            print line

        print "seek函数:"
        with open("dd","r+") as f:
            old = f.read()
            print "内容是:",old
            f.seek(2)
            f.write("liwen is very googd!!!!")

    def makircd(self):
        print "calendar.setfirstweekday()设置每周的起始日期码。0(星期一)到6(星期日)。"
        calendar.setfirstweekday(2)
        print calendar.month(2018,3)

    def print_walk(self):
        dir_num = 0
        file_num = 0
        for root,dirs,files in os.walk("/Users/zhouhaijun/Desktop/hhhhh/",topdown=False):
            for name in files:
                file_num += 1
            for dir in dirs:
                dir_num += 1
        print dir_num
        print file_num

    def data_chuli(self):
        with open("phone.dat","r") as f:
            for line in f.readlines():
                filename = line[:14]
                continuelist = line[14:]
            with open(filename+".txt",+"w") as f1:
                f1.write(continuelist)

    def pirnt_inputfile(self):
       #print "替换"
       # for line in fileinput.input("phone.dat"):
       #     line = line.replace("20160216000121","data")
       #     print line

       # with open("phone.dat","r+") as f:
       #      f.seek(0,2)
       #      print f.tell()
       #      f.write("liwen")
       #      f.write(str(range(1,101)))
       #      f.write("\n")
       #      f.write(str(random.randint(1,101)))
       #
       #      print "指向到第一"
       #      f.seek(0,0)
       #      print f.read()
       # ncount = 0
       # with open("phone.dat","r") as f:
       #     for line in f.readlines():
       #         print line
       #         for le in line:
       #             #print le
       #             if le in string.lowercase or le in string.uppercase:
       #                 ncount += 1
       #                 break
       #
       # print ncount

       w = ["\nliwen is very good!!!\n"]
       with open("phone.dat","r+") as f:
            # con = f.read(2)
            # print con
            # f.seek(0,0)
            # f.writelines(w)
            # f.seek(0,0)
            # print f.read()
            # print "\n"
            print "*"*10
            for i in f.readline(2):
                #print "read\n"
                print i
       a = "I am a bay a good a bod boy"
       re = {}
       for i in a:
           re[i] = a.count(i)
       print re

    def thuday(self):
        print "统计一个字符串每个字母出现的次数"
        s = "adwerewwrdasfdfsdddsddffeee"
        res = {}
        for i in s:
            res[i] = s.count(i)
        print res
        print "2个长度相同list,一个里面的做字典的key,另一个做value,请写个函数实现"
        a = [1, "2", [3, 4], (5, 6), {7: 8}]
        b = [0,1,2,3]
        d = {}
        for i in range(len(a)):
            if not isinstance(a[i] ,(int,float,complex,long,str,unicode,tuple)):
                continue
            else:
                d[a[i]] = b[i]
        print d

        print "有一个长度是101的数组,存在1~100的数字,有一个是重复的,拿重复的找出来"
        nu = range(100)
        rnu = random.randint(0,99)
        nu.insert(rnu,rnu)
        print rnu
        for i in nu:
            if nu.count(i) == 2:
                print i
        numb = [i for i in nu if nu.count(i) == 2]

        print "res",numb
        a = [[1, 2, [3, 4]], 2, [3, 4, [7, 9]]]
        print a[0][1]
        print a[1]
        print [2][0]
    def word_lib(self):

        book_list_in_library = []
        ready_borrow_book_list = []
        borrowed_book_list = []

        menu_info = """
        input 1:add new book to library
        input 2:borrow book from library
        input 3:list all books in library
        input 4:list all borrowed books in library
        input 5: list current books in library
        input 6:lend a book
        """
        a = [1, 2, 3, 4, 4, 5, 6, 6, 7, 67, 7, 2]
        res = []
        for i in a:
            if i not in res:
                res.append(i)
        print res

        d = {}
        print list(d.fromkeys(a))
        print "自己写一个遍历删除"
        for i in a:
            if i == 4:
                a.remove(i)
        print a

        print "统计list中有多少个list"
        alist = [1, [2], [3], 'a']
        ncount = 0

        for i in range(len(alist)):
            if isinstance(alist[i],list):
                ncount += 1
        print ncount

        print reduce(lambda x,y:x+y,[1,2,3,4])

    def mingziyu(self):
        name_list = ['foster', "janet", 'jessus', 'david']
        a = {}
        for i in name_list:
            a[i] = "".join(name_list).count(i[0])
        print a

    def memory_stat(self):
        mem = {}
        f = open("/proc/meminfo")
        lines = f.readlines()
        f.close()
        for line in lines:
            if len(line) < 2: continue
            name = line.split(':')[0]
            var = line.split(':')[1].split()[0]
            mem[name] = long(var) * 1024.0
        mem['MemUsed'] = mem['MemTotal'] - mem['MemFree'] - mem['Buffers'] - mem['Cached']
        return mem

    def print_top(self):
        time2sleep = 1.5
        while True:
            print os.popen('top -n 1').read().split('\n')[2]
            time.sleep(time2sleep)

    def file_walk(self):
        a = [1,2,3,4,5,6,6]
        #print time.strptime(time.localtime(),"%Y-%m-%d %H:%M:%S")
        result = []
        for i in range(2000,3000):
            if i%7 == 0 and i % 5!= 0:
                result.append(str(i))
        print ",".join(result)

    def find_longest_word(self,sentence):
        if not isinstance(sentence,(str,unicode)):
            return None

    def BiarySearch(self,arr,key):
        min = 0
        max = len(arr) -1

        if key in arr:
            while 1:
                center = int((min + max)/2)
                if arr[center] > key:
                    max = center -1
                elif arr[center] < key:
                    min = center + 1
                elif arr[center] == key:
                    print (str[key]) + "The %d position in the array."%str(center)
                    return arr[center]
        else:
            print "There is no such number!!"

    def same_differer(self,lista,listb):
        sam_part = []
        different_path = []

        for i in lista:
            if i in listb:
                sam_part.append(i)
            else:
                different_path.append(i)

        for j in listb:
            if j not in lista:
                different_path.append(i)
        print "The separation result is:",sam_part
        print "The separation result is:",different_path

    def MkdirDay(self,log):
        ThisDay = time.strftime("%m-%d", time.localtime())
        try:
            if os.path.exists(log):
                print "Directory exists"
                cddir = os.getcwd()
                newdir = cddir+"/"+log
                os.chdir(newdir)
                if not os.path.exists(str(self.NextYear)+"-"+str(ThisDay)):
                    os.mkdir(str(self.NowYear)+"-"+str(ThisDay))
                if not os.path.exists(str(self.LastYear)+"-"+str(ThisDay)):
                    os.mkdir(str(self.LastYear)+"-"+str(ThisDay))
                if not os.path.exists(str(self.NextYear)+"-"+str(ThisDay)):
                    os.mkdir(str(self.NextYear)+"-"+str(ThisDay))
                    ll = os.popen("ls")
                    for i in ll:
                        print i,
                print "Creating a successful"
            else:
                print "Directory does not exist"
                os.mkdir("log")
                cddir = os.getcwd()
                newdir = cddir+"/"+log
                os.chdir(newdir)
                if not os.path.exists(str(self.NowYear)+"-"+str(ThisDay)):
                    os.mkdir(str(self.NowYear)+"-"+str(ThisDay))
                if not os.path.exists(str(self.LastYear)+"-"+str(ThisDay)):
                    os.mkdir(str(self.LastYear)+"-"+str(ThisDay))
                if not os.path.exists(str(self.NextYear)+"-"+str(ThisDay)):
                    os.mkdir(str(self.NextYear)+"-"+str(ThisDay))
                ll = os.popen("ls")
                for i in ll:
                    print i,
                print "Creating a successful"
        except:
            print "Creating a failure!!!!"

    def DirLog(self):
        dir = os.getcwd()
        print "当前目录是:",dir
        t = time.time()
        print t
        ThisTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        new_thisTIme = ThisTime.replace(" ", "-")
        print new_thisTIme

        ThisTime = time.strftime("%m-%d", time.localtime())

        #去年今天的日期、
        last_year_month_day = str(self.LastYear) + "-" + str(ThisTime)
        # 当前日期(年月日)、
        this_year_month_day = str(self.NowYear) + "-" + str(ThisTime)
        # 明年今天的日期
        next_year_month_day = str(self.NextYear) + "-" + str(ThisTime)

        print "去年%s,今年%s,明年%s,年月日%s"%(self.LastYear,self.NowYear,self.NextYear,ThisTime)

        dir_list = [last_year_month_day, this_year_month_day, next_year_month_day]
        for i in dir_list:
            print i
        print "*"*10,dir_list

        day_num_in_this_year = time.strftime("%j")
        week_num_in_this_year = time.strftime("%U")

        week_day = time.strftime("%w")
        if week_day == 0:
            week_day = u"星期日"
        else:
            week_day = u"星期" + str(week_day)

        cdPat = os.getcwd() + "/" + "log" #目录路径
        print "当前目录",cdPat
        if not os.path.exists("log"):
            os.mkdir("log")
            os.chdir(cdPat)
            for dirLin in dir_list:
                if not os.path.exists(dirLin):
                    os.mkdir(dirLin)
        else:
            print "已经存在"
            os.chdir(cdPat)
            for dirLin in dir_list:
                if not os.path.exists(dirLin):
                    os.mkdir(dirLin)
                else:
                    print "文件目录已经存在!!"

        for i in dir_list:
            os.chdir(dir)
            dd = os.getcwd() +"/"+"log"+"/"+i
            os.chdir(dd)
            with open(day_num_in_this_year+".text","w") as fp:
                fp.write(str(week_num_in_this_year)+"\n")
                fp.write(week_day.encode("utf-8")+"\n")
        print "操作完毕!!"

    def dirfind(self):
        week_day_dict = {"m": "monday", "tu": "tuesday", "w": "wednesday", "th": "thrusday", "f": "friday",
                         "sa": "saturday", "su": "sunday"}

        user_input = raw_input("input the week day abbreviation:")

        try:
            print "%s is %s" % (user_input, week_day_dict[user_input])
        except:
            print "输入有吴"

    def howMany(self):
        L = ['a', 'abc', 'd', 'abc', 'fgi', 'abf', "d", "d", "d"]
        letter_dir = {}
        for i in L:
            if letter_dir.has_key(i[0]):
                letter_dir[i[0]] += 1
            else:
                letter_dir[i[0]] = 1
        max_occurence = max(letter_dir.values())
        for k ,v in letter_dir.items():
            if v == max_occurence:
                print "letter %s occur %s times." %(k,v)
        print "第二种:"
        new_l = "".join(L)
        print "this is here:",new_l
        new_dir = {}
        for i in new_l:
            new_dir[i] = new_l.count(i)

        print new_dir

        max_new = max(new_dir.values())

        print max_new
        for k,v in new_dir.items():
            if v == max_new:
                print "结果是:","letter %s occur %s times." % (k, v)

    def Wordprocessing(self):
        word_dir = {}
        word_list = ["cinema","iceman","maps","spam","aboard","abroad"]

        for i in word_list:
            if word_dir.has_key(tuple(set(i))):
                word_dir[tuple(set(i))] = word_dir[tuple(set(i))] + " "+i
            else:
                word_dir[tuple(set(i))] = i
        for v in word_dir.values():
            print " ".join(sorted(v.split(" ")))

    def pingIp(self):
        content = []
        fliename = "ip.txt"

    def filename01(self,fname):
        ls = os.linesep

        while True:
            if os.path.exists(fname):
                print "ERROR: '%s' already exists"%fname
            else:
                break

        all = []
        print "\nEnter lines('.by itself to quit').\n"
        while True:
            enter = raw_input('>')
            if enter == '.':
                break
            else:
                all.append(enter)

        fobj = open(fname,'w')
        fobj.writelines('%s%s'%(x,ls) for x in all)
        fobj.close()
        print 'DONE!'

        try:
            fobj = open(fname,'r')
        except IOError,e:
            for eachLine in fobj:
                print eachLine,
            fobj.close()

    def cd0(self):

        s = "aaabbbbccddxxxxffffoooojjiuuhhu"
        d = {}
        for i in s:
            d[i] = s.count(i)
        print d

        print map(lambda x:s.count(x),s)

if __name__ == "__main__":
    mo = Monday(10)
    mo.cd0()

    #mo.Wordprocessing()
    #mo.DirLog()
    # dd = "ddd,sdewrwqe,wer,wer,ewrewq,eeee"
    # mo.find_longest_word(dd)
    # a = [1,2,3,4,5,6,6]
    # b = [3,4,5,3,42,3,42,1]
    # mo.same_differer(a,b)

    #mo.word_lib()
    #mo.thuday()
    #mo.mingziyu()
    #mo.memory_stat()
    #mo.print_top()

    #mo.pirnt_inputfile()
    #mo.print_walk()
    #mo.makircd()

    #mo.file_os()

    #mo.print_re()
    #print mo.myjion("abc","*")

    #mo.max_01()
    #mo.mvbs()
    #print "".join(map(mo.print_22,"KKKKKSSxxx"))
    # n = [1,2,3,4,5,6]
    # print mo.print_20(n)
    #print mo.print_19(1,3,4,5,5)

    #print mo.print_18(s)
    #mo.print_12()
    #mo.print_11()
    #print mo.print_10()
    # print '\n'
    # mo.print_09()
    #
    # print "打印list列表值:\n"
    # movies = ["the holy grail", 1975, "terry jones & terry illliam", 91,
    #           ["graham chapman", ["michael palin", "jonh clees", "terry cilliam", "eric idile", "terry jones"]]]
    # mo.print_08(movies)
    #
    # a = [2, [3, 44, 4, [34, 545, 43434, 'ds']]]
    # mo.print_01()
    # mo.print_02()
    # mo.print_03()
    # mo.print_04()
    # a = "please input a sentence isverygoode!"
    # mo.print_05(a)
    # print mo.pass_06()
    # mo.print_07()

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • Pandas内存优化和数据加速读取

    一个现象是,在使用pandas进行数据处理的时候,加载大的数据或占用很大的内存和时间,甚至有时候发现文件在本地明明不大,但是用pandas以DataFram...

    double
  • Python爬虫进阶必备 | 某裁判文书检索网站加密分析与自动登录实现

    首先是 _csrf ,这个参数比较简单,一般是用来防止跨域攻击的,感兴趣的朋友可以借助搜索引擎了解一下,不是重点我们就不详聊了。

    咸鱼学Python
  • IPython 常用的6个魔术命令

    IPython 的「魔术」是 IPython 基于 Python 标准语法的一系列提升。魔术命令包括两种方法:行魔术命令(line magics):以 % 为前...

    double
  • 12种主流编程语言输出“ Hello World ”,把我给难住了!

    作为一名程序员,在初步学习编程想必都绕不开一个最为基础的入门级示例“Hello World”,那么,你真的了解各个语言“Hello World”的正确写法吗?

    AI科技大本营
  • 爬虫 (十) 学习 python 基础知识点的正确姿势 (三)

    我会以比较学习的方式,主要拿Python和我之前学习的javascript进行比较,拿学习javascript的学习经历来迁移到学习Python,如果你在此之前...

    公众号---志学Python
  • 使用一行Python代码从图像读取文本

    处理图像不是一项简单的任务。对你来说,作为一个人,很容易看着某样东西然后马上知道你在看什么。但电脑不是这样工作的。

    磐创AI
  • 爬虫 (十一) 学习 python 基础知识点的正确姿势 (四)

    我会以比较学习的方式,主要拿Python和我之前学习的javascript进行比较,拿学习javascript的学习经历来迁移到学习Python,如果你在此之前...

    公众号---志学Python
  • 使用自己的数据集训练MobileNet、ResNet实现图像分类(TensorFlow)| CSDN博文精选

    之前写了一篇博客《使用自己的数据集训练GoogLenet InceptionNet V1 V2 V3模型(TensorFlow)》https://panjinq...

    AI科技大本营
  • 爬虫 (八) 学习 python 基础知识点的正确姿势 (一)

    我会以比较学习的方式,主要拿Python和我之前学习的javascript进行比较,拿学习javascript的学习经历来迁移到学习Python,如果你在此之前...

    公众号---志学Python
  • 谁说Python不适合做GUI程序?wxFormBuilder上手教程

    来源:https://blog.csdn.net/caiza3491/article/details/79529966

    小草AI

扫码关注云+社区

领取腾讯云代金券