-2

I'm looking for converting a list of strings separated by comma to a single element like so:

my_list=['A','B','B','C','C','A']

I want the output to be:

my_list=['ABBCCA']
Sociopath
  • 12,395
  • 17
  • 43
  • 69

4 Answers4

2

Use join:

my_list = ["".join(my_list)]
print(my_list)

Output:

['ABBCCA']
Austin
  • 25,142
  • 4
  • 21
  • 46
Sociopath
  • 12,395
  • 17
  • 43
  • 69
1

Use str.join:

>>> my_list= ['A','B','B','C','C','A']
>>> "".join(my_list)
'ABBCCA'

So in your case, enclose it in a list:

>>> ["".join(my_list)]
['ABBCCA']
Netwave
  • 36,219
  • 6
  • 36
  • 71
0

you can concat str by join:

my_list = ['A', 'B', 'B', 'C', 'C', 'A']
print(''.join(my_list))   # 'ABBCCA'

if you mean split comma in one string, like:

s = 'A,B,B,C,C,A'
print(''.join(s.split(',')))   # 'ABBCCA'  
recnac
  • 3,663
  • 6
  • 22
  • 46
0

You can use a loop too:

str=''
for i in my_list:
     str+=i
print(str)