1

I have a variable called result which is equal to this list [[0, ''], [1, ''], [2, ''], [3, 'x'], [4, 'x']]. I want to change that list into 'xx', so I can print that data to the screen of the player. Anyway I could do this?

My attempt so far:

res = [''.join(ele) for ele in str(result)]

Output:

['[', '[', '0', ',', ' ', "'", '', "'", ']', ',', ' ', '[', '1', ',', ' ', "'", '', "'", ']', ',', ' ', '[', '2', ',', ' ', "'", '', "'", ']', ',', ' ', '[', '3', ',', ' ', "'", 'x', "'", ']', ',', ' ', '[', '4', ',', ' ', "'", 'x', "'", ']', ']']
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Thornily
  • 533
  • 3
  • 15

1 Answers1

3

You could use str.join with a comprehension:

>>> result = [[0, ''], [1, ''], [2, ''], [3, 'x'], [4, 'x']]
>>> result_str = ''.join(xs[1] for xs in result)
>>> result_str
'xx'
Sash Sinha
  • 18,743
  • 3
  • 23
  • 40