0

I have code that generates a list (target = [ ]) by appending strings (token) to it.

Now I have another list say A = [['A', 'B'], ['C', 'D']] that I would like to add to the target list, without touching the original list. Just add on to the original, may I know how to do it? thanks

    def read_samples_by_string(self, path):
        for tokens in self.read_tokens(path):

            target =  []
            print(type(target))  # this is <type 'list'>
            
            for token in tokens:
                
                target.append(token)
                print(type(token))   # this is <type 'str'>               
            yield target
            print(target)

Input list : 
A = [['A', 'B'], ['C', 'D']]

output :
['O','X', 'Y', 'Z']
['L', 'M'] 
['J', 'K', 'W'] 

Expected output
['O','X', 'Y', 'Z']
['L', 'M'] 
['J', 'K', 'W'] 
['A', 'B']
['C', 'D']
1
  • How you are exporting the query? Commented May 24, 2020 at 3:12

1 Answer 1

2
final_list = []
list1 = [['A', 'B'], ['C', 'D']]
list2 = [['O','X', 'Y', 'Z'],['L', 'M'],['J', 'K', 'W']]

for l2 in list2:
    final_list.append(l2)

for l1 in list1:
    final_list.append(l1)

for l in final_list:
    print(l)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.