python list of numbers converted to string incorrectly

前端 未结 4 1062
悲&欢浪女
悲&欢浪女 2020-12-20 17:28

For some reason, when I do the code...

def encode():
    result2 = []
    print result  
    for x in result:  
        result2 += str(x)  
    print resul         


        
4条回答
  •  臣服心动
    2020-12-20 17:54

    Using map http://docs.python.org/library/functions.html#map

    In [2]: input_list = [123, 456, 789]
    In [3]: output_list = map(lambda x:str(x), input_list)
    In [4]: output_list
    Out[5]: ['123', '456', '789']
    

提交回复
热议问题