zoukankan      html  css  js  c++  java
  • python学习笔记四

    数据处理
     
    1.原地排序:list.sort
    2.复制排序:sorted
    3.方法串联:line.strip().split()
    4.函数串联:sort(foo(list.item))
    5.列表转换:newl=[ s.upper() for s in old_l]
    6.工厂函数:  uniq_newl=set(newl)
    7.分片:print(newl[0:3])
     
     
     
    import os

    dataPath="F:\book\python\headfirst python book&&code\code\chapter5\data"


    def sanitize(time_string):
        if ":" in time_string:
            min,sec=time_string.split(":")
        elif "-" in time_string:
            min,sec=time_string.split("-")

        if 'min' in locals():
            return min+"."+sec
        else:
            return time_string

    try:
       
        fileList=os.listdir(dataPath)
        fileData=[]
        for fileName in fileList:
            print(fileName)
            listData=[]
            with open(fileName) as dataout:
                line=dataout.readline()
                """
                for word in line.strip().split(","):
                    listData.append(sanitize(word))
                """
                #转换列表
                listData=[sanitize(each_it) for each_it in line.strip().split(",")]
            fileData.append(listData)


     
        for data in fileData:
            #删除重复数据
            """
            tmplist=[]
            for item in data:
                if item not in tmplist:
                    tmplist.append(item)
            """
            tmplist=set(data) #自动删除重复数据
            print(sorted(tmplist)[0:3])

    except IOError as err:
        print("IOError:"+err)
  • 相关阅读:
    机房收费系统——报表(2)
    机房收费系统——报表(1)
    机房收费系统之结账
    机房管理系统——vb与excel链接2
    机房管理系统——VB与Excel的链接
    Unity
    Android Dev Tips
    Android JSON And Object Cast
    Android Screen Orientation
    iOS8 with Swift
  • 原文地址:https://www.cnblogs.com/manziluo/p/5800223.html
Copyright © 2011-2022 走看看