11

Possible Duplicate:
Merge two lists in python?

How can I prepend list elements into another list?

A = ['1', '2']
B = ['3', '4']
A.append(B)
print A

returns

['1', '2', ['3', '4']]

How can I make it

['1', '2', '3', '4']?
Community
  • 1
  • 1
ewhitt
  • 897
  • 1
  • 12
  • 18

3 Answers3

12
A.extend(B)

or

A += B

This text added to let me post this answer.

kindall
  • 178,883
  • 35
  • 278
  • 309
2

list.extend, for example, in your case, A.extend(B).

Cat Plus Plus
  • 125,936
  • 27
  • 200
  • 224
-2

this can also be done as

for s in B: 
    A.append(B)

of course A.extend(B) does the same work but using append we need to add in the above f

jamylak
  • 128,818
  • 30
  • 231
  • 230
kiranmai
  • 17
  • 1