-2

If you have

x = ['A', 'B', 'C']
y = ['D', 'E', 'F']

then you can calculate:

x+y # ['A', 'B', 'C', 'D', 'E', 'F']

But if you do

sum([x,y])

you get

TypeError: unsupported operand type(s) for +: 'int' and 'list'

Any idea why?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Myccha
  • 961
  • 1
  • 11
  • 20
  • 2
    Sure, [Summing a list of lists](https://stackoverflow.com/questions/48536659/summing-a-list-of-lists) – mkrieger1 Aug 22 '21 at 22:59

1 Answers1

6

Its, because sum allways 'adds' the start element which defaults to 0. Try

sum([x,y], start=[])
H. Doebler
  • 633
  • 4
  • 9