0

am trying to add a list of lists to a list

a = [['xx',''ee', 'yy'], [1,2,3]]

existing = [['zz', 'ss', 'ww'], [4,5,6]]

what is the best way add elements of a into the existing list

expected = [['zz', 'ss', 'ww'], [4,5,6], ['xx',''ee', 'yy'], [1,2,3]]
pylearner
  • 1,358
  • 2
  • 10
  • 26

2 Answers2

1

Either use extend or + for concatenation as:

a = [['xx','ee', 'yy'], [1,2,3]]
b = [['zz', 'ss', 'ww'], [4,5,6]]
b = b + a
print(b)

a = [['xx','ee', 'yy'], [1,2,3]]
b = [['zz', 'ss', 'ww'], [4,5,6]]
b.extend(a)
print(b)
Krishna Chaurasia
  • 8,924
  • 6
  • 22
  • 35
0
expected = existing + a
print(expected)

output is :

[['zz', 'ss', 'ww'], [4, 5, 6], ['xx', 'ee', 'yy'], [1, 2, 3]]
Nagmat
  • 373
  • 4
  • 14