2

In python

a = [['z', 'G', 'j', 'E', 'U'], ['%', '#', '(', '!', ')'], ['6', '4', '8', '1', '3']]

I want to print above nested list into character which are side by side example output:

zGjEU%#(!)64813

How to do that?

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
amul
  • 11
  • 3
  • 1
    Does this answer your question? [How to concatenate (join) items in a list to a single string](https://stackoverflow.com/questions/12453580/how-to-concatenate-join-items-in-a-list-to-a-single-string) – Jonathan Ciapetti Dec 11 '22 at 04:57
  • What have you tried so far? It will be easier to help you if you give it your best shot first! :^) – rhurwitz Dec 11 '22 at 04:57

2 Answers2

2

Consider a nested comprehension along with str.join:

>>> a = [['z', 'G', 'j', 'E', 'U'], ['%', '#', '(', '!', ')'], ['6', '4', '8', '1', '3']]
>>> print(''.join(c for chars in a for c in chars))
zGjEU%#(!)64813
Sash Sinha
  • 18,743
  • 3
  • 23
  • 40
1
a = [['z', 'G', 'j', 'E', 'U'], ['%', '#', '(', '!', ')'], ['6', '4', '8', '1', '3']]
result = ""
for item in a:
    for char in item:
        result += char

result:

'zGjEU%#(!)64813'
Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
User12
  • 138
  • 8