I have a list:
listA = [('xxx@gmail.com\n',), ('111@gmail.com\n',)]
What i trying achieved is to remove the ()
and \n
in each list's item.
Expected Output:
listA = ['xxx@gmail.com', '111@gmail.com',]
I did my researched but every articles online is about removing the square bracket but not ()
The problem is the comma, not the brackets: ('a',)
is a tuple
, while ('a') == 'a'
. Just get the item inside each tuple (I throw in some strip
ping as well because you have \n
s in the input and not in the expected output):
listA = [t[0].strip() for t in listA]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.