Q: Python list group by date,name I've a list like below:
list=[['BMW Z4', 'TEST', 18, '2016-09-26'],
['BMW Z4', 'TEST', 144, '2014-10-30'],
['BMW 335i', 'TEST', 144, '2013-09-26'],
['BMW 335i', 'TEST', 360, '2014-08-31'],
['BMW 335i', 'TEST', 360, '2017-08-31'],
['BMW 550xd', 'TEST', 18, '2016-10-30'],
['BMW 550xd', 'TEST', 36, '2014-10-30']]

I'm trying create:
list2=[['BMW Z4', 'TEST', 162, '2016-09-26','2014-10-30'],
['BMW 335i', 'TEST', 864, '2017-08-31','2013-09-26'],
['BMW 550xd', 'TEST', 54, '2016-10-30','2014-10-30']]



*

*1) List is grouped by the very first element

*2) Quantity is sum(third element)

*3) New column is added forth element is newts date    and the fifth
is the oldest one.


Do You have any suggestion how I can get table like list2 using Python functions ? 

A: You can use itertools.groupby():
from itertools import groupby

lst = [['BMW Z4', 'TEST', 18, '2016-09-26'],
       ['BMW Z4', 'TEST', 144, '2014-10-30'],
       ['BMW 335i', 'TEST', 144, '2013-09-26'],
       ['BMW 335i', 'TEST', 360, '2014-08-31'],
       ['BMW 335i', 'TEST', 360, '2017-08-31'],
       ['BMW 550xd', 'TEST', 18, '2016-10-30'],
       ['BMW 550xd', 'TEST', 36, '2014-10-30']]

lst2 = []

for k, g in groupby(lst, lambda x: x[0]):
    g = list(g)
    lst2.append([k, "TEST", sum(x[2] for x in g), max(x[3] for x in g),
                 min(x[3] for x in g)])
print(lst2)

Output:   
[['BMW Z4', 'TEST', 162, '2016-09-26', '2014-10-30'],
 ['BMW 335i', 'TEST', 864, '2017-08-31', '2013-09-26'],
 ['BMW 550xd', 'TEST', 54, '2016-10-30', '2014-10-30']]


A: You could use Pandas to do this
import pandas as pd

list1=[['BMW Z4', 'TEST', 18, '2016-09-26'],
       ['BMW Z4', 'TEST', 144, '2014-10-30'],
       ['BMW 335i', 'TEST', 144, '2013-09-26'],
       ['BMW 335i', 'TEST', 360, '2014-08-31'],
       ['BMW 335i', 'TEST', 360, '2017-08-31'],
       ['BMW 550xd', 'TEST', 18, '2016-10-30'],
       ['BMW 550xd', 'TEST', 36, '2014-10-30']]

result = pd.DataFrame(list1).groupby(0, as_index=False).agg({1:'first', 2:'sum', 3:['max', 'min']}).values

print(result)

Which will give you:
[['BMW 335i' 'TEST' 864 '2017-08-31' '2013-09-26']
 ['BMW 550xd' 'TEST' 54 '2016-10-30' '2014-10-30']
 ['BMW Z4' 'TEST' 162 '2016-09-26' '2014-10-30']]

(note you shouldn't name your variable 'list', as this overrides the built in type)

A: You can also use pandas
import pandas as pd
import numpy as np

df = pd.DataFrame(l)

           0     1    2           3
0     BMW Z4  TEST   18  2016-09-26
1     BMW Z4  TEST  144  2014-10-30
2   BMW 335i  TEST  144  2013-09-26
3   BMW 335i  TEST  360  2014-08-31
4   BMW 335i  TEST  360  2017-08-31
5  BMW 550xd  TEST   18  2016-10-30
6  BMW 550xd  TEST   36  2014-10-30


l2 = df.groupby(0).agg({1: 'first', 2:np.sum, 3: [np.max, np.min]}).reset_index().values.tolist()

l2

[['BMW 335i', 'TEST', 864, '2017-08-31', '2013-09-26'],
 ['BMW 550xd', 'TEST', 54, '2016-10-30', '2014-10-30'],
 ['BMW Z4', 'TEST', 162, '2016-09-26', '2014-10-30']]

Also, don't call your lists, list

A: You can use defaultdict:
from collections import defaultdict

data = [
    ['BMW Z4', 'TEST', 18, '2016-09-26'],
    ['BMW Z4', 'TEST', 144, '2014-10-30'],
    ['BMW 335i', 'TEST', 144, '2013-09-26'],
    ['BMW 335i', 'TEST', 360, '2014-08-31'],
    ['BMW 335i', 'TEST', 360, '2017-08-31'],
    ['BMW 550xd', 'TEST', 18, '2016-10-30'],
    ['BMW 550xd', 'TEST', 36, '2014-10-30'],
]

d = defaultdict(lambda: {'sum': 0, 'dates': set()})
for row in data:
    d[row[0]]['sum'] += row[2]
    d[row[0]]['dates'].add(row[3])

result = [
    [key, 'TEST', value['sum']] + sorted(value['dates'], reverse=True)
    for key, value in d.items()
]

Btw, it's not good to use list as a name of a variable. 
