0

Edit: I realize the question is confusing now, so I will try to clarify. For the code I am using I don't know what the lists that are being outputted are. All I know is that (using the example) when I print(j), it turns out like the output I have put below. I hope that clears up any confusion.

I am creating a program that will use OCR to read documents then output text. The problem is for the program to work I need the text output to be a list. How can I convert it to a list?

This is not the specific code but an example.

l = ['3']
m = ['2']
n = ['1']
for j in (l,m,n):
        print(j)

In this example I can't change j or anything before j.

The output:

['3']
['2']
['1']

The real code has b = list but I can't change any of the code before b.

I want it to look like this:

['3', '2', '1']
  • Hey You can look at my answer for other possible ways for concatenating as well. – 0xPrateek Jun 12 '19 at 18:28
  • There are many options and some of them are present in answers. Was just curious why there is only one element in all of the `list`? I would opt of variables rather. – mad_ Jun 12 '19 at 18:36

2 Answers2

1

When you did (l,m,n) that made a tuple object. You can append lists using the + operator.

l = ['3']
m = ['2']
n = ['1']
j = l + m + n
print(j)

output:

['3', '2', '1']
0

list concatenation works with the addition sign:

new_list = l + m + n
Alec
  • 8,529
  • 8
  • 37
  • 63