37,721
社区成员
发帖
与我相关
我的任务
分享
>>> s = 'book, pen,mp3,ball,room, ball,pen,phone'
>>> result = ','.join(set( [ i.strip() for i in s.split(',')] ))
>>> s
'book, pen,mp3,ball,room, ball,pen,phone'
>>> result
'ball,room,phone,pen,book,mp3'
#!/usr/bin/env python
#Loving Python
#-*- coding=utf-8 -*-
userdict = {}
strings = 'book,pen,mp3,ball,room,ball,pen,phone'
for string in strings.split(','):
if string not in userdict:
userdict[string] = 1
else:
pass