"".join(reduce(lambda i1,i2:i1+i2 ,[["*",str(len(argv)),"\r\n"]] + [["$",str(len(p)),"\r\n",p,"\r\n"] for p in map(str,argv)]))
搞定,如果加个头定义成函数就两行:
def parseCommand(*argv): return "".join(reduce(lambda i1,i2:i1+i2 ,[["*",str(len(argv)),"\r\n"]] + [["$",str(len(p)),"\r\n",p,"\r\n"] for p in map(str,argv)]))