-1

I am new to python and I am not getting how to print the list in which, the list should not contain ' while printing.

if give print list I am getting the result as ['xyz', 'ysfe'] I need to eliminate that single quotes.

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
Codingkido
  • 53
  • 9
  • 1
    You want to eliminate single quotes but leave the brackets? Why? – Reut Sharabani Feb 26 '18 at 16:38
  • 3
    Something like `print('[{}]'.format(', '.join(l)))` would work. I don't really see the point though. – Patrick Haugh Feb 26 '18 at 16:44
  • Please do post the reason you are looking for such a solution. Also before asking a question, please do search stackoverflow if its already answered. It makes this community a better place and you also learn along the way. Thanks. – Adarsh Feb 26 '18 at 16:46
  • (Don't add tags willy-nilly. Your example is an error in Python 3.x.) The function `print` expects a *string*. If you give it something entirely different – "here, have a list and see what you can do with it" – it calls the object's `__str__` method to get a string rep. And you cannot influence that. – Jongware Feb 26 '18 at 16:48
  • Note: avoid using the variable name of `list` as this will replace the builtin Python function `list()` – Martin Evans Feb 26 '18 at 18:40

4 Answers4

2

try this, it will work

mylist = ['abc', 'def', 'brt']
print ('[%s]' % ', '.join(map(str, mylist)))
Harsh Bhut
  • 238
  • 2
  • 14
2
a=['xyz', 'ysfe']
print(str(a).replace("'",''))

Try this

whackamadoodle3000
  • 6,684
  • 4
  • 27
  • 44
1
lst = ['xyz', 'ysfe']
print(str(lst).translate(str.maketrans('', '', "'")))

try this, it will work

illright
  • 3,991
  • 2
  • 29
  • 54
gjxhlan
  • 11
  • 2
0
a = ['xyz', 'ysfe']
s = {39: None}
print(str(a).translate(s))
vijju
  • 21
  • 2
  • 3
    Add a little context by saying why your code works. That way it might help the OP and others as well. – Shravan Mar 03 '20 at 07:20