-1

I'm trying to have trinket print out an entire list without printing the quotation marks surrounding each index. A plain print(list) isn't working, and neither are any of the more elaborate options such as print(*list, sep =', '). I'm relatively new to coding so apologies if this request is impossible/ridiculously easy. What I'm trying to avoid: ['a','b','c','d']

  • Then don't print the *list* but only its items. Quoting text strings is one of the things Python does by default, when printing a list. – Jongware Jan 26 '20 at 21:08
  • @Mark Meyer I guess he only wants to get rid of the quotations, not the brackets. – Jordan Brière Jan 26 '20 at 21:14
  • The apostrophes are there, because the are practically always useful. It may be important, whether you have the number *9* or a string containing the digit 9. If you are absolutely sure, that your list contains just strings, you should have stated so. – guidot Jan 26 '20 at 21:22

1 Answers1

0

You could simply use str.join to represent the list yourself. E.g.

lst = ['a','b','c','d']

print(f'[{", ".join(lst)}]')
Jordan Brière
  • 1,045
  • 6
  • 8
  • [@guidot](https://stackoverflow.com/users/1435475/guidot): No, it doesn't. `repr` returns `['a', 'b', 'c', 'd']`, and we replace the `'` with nothing so we get `[a, b, c, d]`. – Jordan Brière Jan 26 '20 at 21:31
  • Fixed wording. Second solution suffers from filtering the quotes also, if they were within a string. I can't imagine that as expected behavior. – guidot Jan 26 '20 at 21:33
  • Yes, that's true. If the elements contains any apostrophe then they will also be stripped. I agree, while this works for the provided example, this indeed cannot be expected behaviour. Removed that solution from the post, thanks. – Jordan Brière Jan 26 '20 at 21:36
  • Unfortunately, the "f" throws up a bad input in trinket - my main problem with any of the methods I've tried to find on the internet. If I remove it I do get a workable result though - so thank you! – user12787412 Jan 27 '20 at 07:33