-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
  • 13,068
  • 19
  • 47
  • 75

4 Answers4

2

Use join:

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

Output:

['ABBCCA']
Austin
  • 25,759
  • 4
  • 25
  • 48
Sociopath
  • 13,068
  • 19
  • 47
  • 75
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
  • 40,134
  • 6
  • 50
  • 93
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,744
  • 6
  • 24
  • 46
0

You can use a loop too:

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