int 类型转化为列表
a = 123321
b = list(map(int, str(a)))
print(b)
结果为[1, 2, 3, 3, 2, 1]
各个元素为int类型
如果想要合并元素 需要先把元素转化为字符串
a = 123321
b = list(map(int, str(a)))
b.sort()
c = []
for i in b:
j = str(i)
c.append(j)
print(c)
d = "".join(c)
print(d)
print(type(d))
打印结果如下
['1', '1', '2', '2', '3', '3']
112233
<class 'str'>
如想要去重 则用set()函数
a = 123321
b = list(map(int, str(a)))
b.sort()
c = []
for i in b:
j = str(i)
c.append(j)
print(c)
c = set(c)
d = "".join(c)
print(d)
print(type(d ))
结果为
['1', '1', '2', '2', '3', '3']
312
<class 'str'>