python:将列表中的整数项连接到单个字符串 [英] python: concatenate integer items in a list to a single string

查看:103
本文介绍了python:将列表中的整数项连接到单个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是否有更好的方法将整数"列表中的项目连接成字符串:

Is there a better way of the following for concatenating items in a list that are "integers" into a string:

import numpy as np
my_list = [1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0]
changed_list = np.char.mod('%d', my_list)
final_ans = ''.join(changed_list )

推荐答案

我不确定您的意思是更好,但您可以尝试一下.

Im not sure what you mean by better, but you could try this.

''.join([str(x) for x in my_list])

这篇关于python:将列表中的整数项连接到单个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆