Easy way to convert a unicode list to a list containing python strings?

前端 未结 9 2121
臣服心动
臣服心动 2020-12-23 16:42

Template of the list is:

EmployeeList =  [u\'\', u\'\', u\'\', u\'\']

I would like to con

9条回答
  •  没有蜡笔的小新
    2020-12-23 17:26

    There are several ways to do this. I converted like this

    def clean(s):
        s = s.replace("u'","")
        return re.sub("[\[\]\'\s]", '', s)
    
    EmployeeList = [clean(i) for i in str(EmployeeList).split(',')]
    

    After that you can check

    if '1001' in EmployeeList:
        #do something
    

    Hope it will help you.

提交回复
热议问题