How to change the list separator in python?

后端 未结 2 2083
忘了有多久
忘了有多久 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: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 ,
    

提交回复
热议问题