0

I have a list of item:

list1 = ['abs', 'cbs', 'dbs']

which I need to convert like this

abs,cbs,dbs

I have used ','.join(list1) which gives me the following output 'abs,cbs,dbs'. Now I am unable to proceed to just remove quotes. I am using python 2.6. Any other way to directly convert list into desired output is most welcome.

This question has answer in itself, the output has been misinterpreted.

cyborg
  • 870
  • 1
  • 15
  • 34
  • 1
    You are confusing the string representation and the actual string itself. You may want to check the length of the string and do `"'" in ','.join(list1)`. The actual string which you are getting is `abs,cbs,dbs` only – thefourtheye Jan 06 '16 at 03:44
  • What's with all the random "close" votes recently? How is this question off-topic? – Gabriel Jan 06 '16 at 03:52
  • @thefourtheye thanks, I was verifying the output in console and have not checked with the final output, working good and thanks for clarifying my concept in python. – cyborg Jan 06 '16 at 03:53

1 Answers1

1

Seems to be working for me (in python3). I think you just need to print the string instead of just looking at the repl.

>>> list1 = ['abs', 'cbs', 'dbs']
>>> print(list1)
['abs', 'cbs', 'dbs']
>>> ','.join(list1)
'abs,cbs,dbs' 

The above repl or representation of what just happened. It prints out automatically when you run statements in the shell. It is just useful output most of the time. It lets you know in this example that the command ,'.join(list1) returned a string (hence the '' around it) with the value of abs,cbs,dbs.

What you are looking for is to print. You can see the results of that here.

>>> print(','.join(list1))
abs,cbs,dbs
Jared Mackey
  • 3,998
  • 4
  • 31
  • 50
  • is there any way to put this in a list without the quotes [abs,cbs,dbs] ? i can't seem to do it with the print statement – dingo Aug 30 '21 at 06:00