1.map map是python内置的高阶函数,它接收一个函数和一个列表,函数依次作用在列表的每个元素上,返回一个可迭代map对象. class map(object): """ map(func, *iterables) --> map object Make an iterator that computes the function using arguments from each of the iterables. Stops when the shortes…
使用list生成dict(可指定单条长度和数据类型,splen为4即为list中每4行组成dict中一条) def list2dict(srclist,splen,datatype):# datatype: 0-str 1-int 2-float dstdict={} for i in range(0,int(len(srclist)/splen)): dstdict[srclist[splen*i]]=[] for j in range(1,splen): if datatype==0: ds…
需求:快速进行ftp上传 ,下载,查询文件 原来直接在shell下操作: 需要[连接,输用户名,输密码,单文件操作,存在超时限制] 太过于繁琐,容易操作失败 脚本改进: 一句命令,搞定多文件上传,下载,查询,列表等操作 后期可以加入更强大的功能 直接上脚本: #!/usr/bin/python #ftp.py #this script is used to make some ftp operations more convenient #add upload and download oper…
在Python教程中return 语句是函数中常用的一个语句.return 语句用于从函数中返回,也就是中断函数.我们也可以选择在中断函数时从函数中返回一个值.案例(保存为 function_return.py): def maximum(x, y): if x > y: return x elif x == y: return 'The numbers are equal' else: return y print(maximum(2, 3)) 输出: $ python function_re…