我想要将一个Unicode Python列表连接在一起,例如:
我该如何加入这个呢?
a = [u'00', u'0c', u'29', u'58', u'86', u'16']
我需要一个类似以下格式的字符串:
'00:0c:29:58:86:16'
我该如何加入这个呢?
>>> a = [u'00', u'0c', u'29', u'58', u'86', u'16']
>>> u":".join(a)
u'00:0c:29:58:86:16'
>>> str(u":".join(a))
'00:0c:29:58:86:16'
这样怎么样:
if __name__ == "__main__":
a = [u'00', u'0c', u'29', u'58', u'86', u'16']
s = u''
j = True
for i in a:
if j == True:
s += i
j = False
else:
s += u':' + i
print s
join()
。 - naeg
b':'.join(str(item) for item in a)
- agfUnicodeDecodeError
错误。有人知道为什么吗? - Rafael S. Calsaverinistr
部分,那是因为该字符无法用ASCII表示。如果你需要将你的Unicode字符串转换成ASCII,你就必须做一个近似处理,可以尝试像这个解决方案一样的方法:https://dev59.com/IGsz5IYBdhLWcg3wJUjJ#8087466 - MattH