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
  • 857
  • 1
  • 11
  • 18

3 Answers3

12
A.extend(B)

or

A += B

This text added to let me post this answer.

kindall
  • 168,929
  • 32
  • 262
  • 294
2

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

Cat Plus Plus
  • 119,938
  • 26
  • 191
  • 218
-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
  • 120,885
  • 29
  • 225
  • 225
kiranmai
  • 17
  • 1