string to list conversion in python

后端 未结 6 2248
借酒劲吻你
借酒劲吻你 2021-01-13 05:25

I have a string.

s = \'1989, 1990\'

I want to convert that to list using python & i want output as,

s = [\'1989\', \'19         


        
6条回答
  •  情书的邮戳
    2021-01-13 05:55

    i created generic method for this :

    def convertToList(v):
        '''
        @return: input is converted to a list if needed
        '''
        if type(v) is list:
            return v
        elif v == None:
            return []
        else:
            return [v]
    

    Maybe it is useful for your project.

    converToList(s)
    

提交回复
热议问题