Re: [Tutor] How sum() works in python

2017-08-01 Thread Steven D'Aprano
On Mon, Jul 31, 2017 at 11:06:18PM -0700, ramakrishna reddy wrote: > > sum([[1,2,3], [3,4,5]], []) returns [1, 2, 3, 3, 4, 5] [] + [1,2,3] + [3,4,5] returns [1, 2, 3, 3, 4, 5]. -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or chang

Re: [Tutor] How sum() works in python

2017-08-01 Thread Abdur-Rahmaan Janhangeer
i guess it adds / sort of concatenates the list On Tue, Aug 1, 2017 at 10:06 AM, ramakrishna reddy wrote: > Hi All, > > I know > > > sum([1,2,3]) returns 6. > > But sum with [] 'empty list' as second parameter returns as below. > > > sum([[1,2,3], [3,4,5]], []) returns [1, 2, 3, 3, 4, 5] > Can a

Re: [Tutor] How sum() works in python

2017-08-01 Thread ramakrishna reddy
nice explanation .. thanks this cleared my doubt >>> k = [20] >>> for i in [[1,2,3],[3,4,5]]: ... k += i ... >>> k [20, 1, 2, 3, 3, 4, 5] On Tue, Aug 1, 2017 at 1:35 AM, Alan Gauld via Tutor wrote: > On 01/08/17 07:06, ramakrishna reddy wrote: > > >> sum([1,2,3]) returns 6. > > > > But sum

Re: [Tutor] How sum() works in python

2017-08-01 Thread Peter Otten
ramakrishna reddy wrote: > Hi All, > > I know > >> sum([1,2,3]) returns 6. > > But sum with [] 'empty list' as second parameter returns as below. > >> sum([[1,2,3], [3,4,5]], []) returns [1, 2, 3, 3, 4, 5] > Can any one please explain this logic ? I searched in google but could not > find the

Re: [Tutor] How sum() works in python

2017-08-01 Thread Alan Gauld via Tutor
On 01/08/17 07:06, ramakrishna reddy wrote: >> sum([1,2,3]) returns 6. > > But sum with [] 'empty list' as second parameter returns as below. > >> sum([[1,2,3], [3,4,5]], []) returns [1, 2, 3, 3, 4, 5] An interesting question, I wasn't aware that you could add lists with sum. However, the resu