全部博文(271)
分类: Python/Ruby
2015-04-25 23:29:39
主要记录下这种用法: columnsList = [column.strip() for column in columnsList]
同样 采用此方式 可以做 replace 等类似的操作
##在CSDN 上 看到一位企鹅同学分享的PPT《编写“高性能”python 代码》 同以上类似的list 处理 ; 这里做个记录
l = range(10000)
def function1():
result = []
for i in l:
if i % 2 == 0:
result.append(i)
return result
def function2():
return [i for i in l if i %2 == 0]
function2 的处理速率是 1 的 1.36倍
同样 采用此方式 可以做 replace 等类似的操作
##在CSDN 上 看到一位企鹅同学分享的PPT《编写“高性能”python 代码》 同以上类似的list 处理 ; 这里做个记录
l = range(10000)
def function1():
result = []
for i in l:
if i % 2 == 0:
result.append(i)
return result
def function2():
return [i for i in l if i %2 == 0]
function2 的处理速率是 1 的 1.36倍
#以下为在 数据格式化用到的部分
String
#2015-04-21 12:21:26 lv3:MS:rolelogin:userId=2:roleId=1006:account=xxxxxx:lev=1:platform=506:mac=:os=2:totalcash=0:hint=0:gate=1:line=4:peer=210.19.x.:from=29101
columnsStr = " userId , roleId,account,lev,platform,mac,os,totalcash,hint,gate,line,peer,from"
columnsList = columnsStr.split(',') #默认,分割
columnsList = [column.strip() for column in columnsList] #对列表中每个元素去空格; strip : 对字段录入时 疏忽导致而加入空格情况处理
处理后结果:
['userId', 'roleId', 'account', 'lev', 'platform', 'mac', 'os', 'totalcash', 'hint', 'gate', 'line', 'peer', 'from']
2015-04-21 19:08:44 lv3:MS:rolelogin:userId=2:roleId=1002:account=8100785:lev=1:platform=506:mac=:os=2:totalcash=0:hint=0:gate=1:line=4:peer=210.19.254.191:from=29101
2015-04-21 19:08:44 2 1002 8100785 1 506 2 0 0 1 4 210.19.254.191 29101