How to change the list separator in python?

后端 未结 2 2082
忘了有多久
忘了有多久 2021-01-29 15:20

I have a list

[u\'Scanned by CamS\\nINCOME TAN DEPARTMENT\\nINDER SINGH\\nAMAR JEETSINGH FIORA\\n2407/1985\\nMimi\\nAAPPF5793,\\nGOVT of INDIA\\n\']
相关标签:
2条回答
  • 2021-01-29 15:27

    using split on first list item (desired string) :

    l = [u'Scanned by CamS\nINCOME TAN DEPARTMENT\nINDER SINGH\nAMAR JEETSINGH FIORA\n2407/1985\nMimi\nAAPPF5793,\nGOVT of INDIA\n']
    l =  l[0].split('\n')
    l # ['Scanned by CamS', 'INCOME TAN DEPARTMENT', 'INDER SINGH', 'AMAR JEETSINGH FIORA', '2407/1985', 'Mimi', 'AAPPF5793,', 'GOVT of INDIA', '']
    

    last element is empty because of last '\n'

    0 讨论(0)
  • 2021-01-29 15:41

    You can try this both..

    a = [u'Scanned by CamS\nINCOME TAN DEPARTMENT\nINDER SINGH\nAMAR JEETSINGH FIORA\n2407/1985\nMimi\nAAPPF5793,\nGOVT of INDIA\n']
    
    print str(a[0]).split('\n')
    #['Scanned by CamS', 'INCOME TAN DEPARTMENT', 'INDER SINGH', 'AMAR JEETSINGH FIORA', '2407/1985', 'Mimi', 'AAPPF5793,', 'GOVT of INDIA', '']
    
    print str(a[0]).replace('\n',' ,')
    #Scanned by CamS ,INCOME TAN DEPARTMENT ,INDER SINGH ,AMAR JEETSINGH FIORA ,2407/1985 ,Mimi ,AAPPF5793, ,GOVT of INDIA ,
    
    0 讨论(0)
提交回复
热议问题