I just saw someone wrote this below and got confused why sum()
could be used to remove the bracket from another list:
pwd = [['x'], ['y'], ['z']]
a = sum(pwd, [])
print(a) // ['x', 'y', 'z']
By looking up sum()
definition…
sum(
iterable
, /,start=0
)`
iterable
can be anything, list, tuples or dictionaries, but most importantly it should be numeric.
start
is added to the sum of numbers in the iterable.
If start
is not given in the syntax, it is assumed to be 0.
How does an empty list as start
argument of sum()
remove the list from another list? This puzzles me…could anyone demystify this?