python 3.x - List of lists list comprehension to compare and sum -
i have list of lists , i'm working python 3:
[[8560915350016, 'horo', 'wafa', ' 8560915350016 - horo wafa', 'august', 2014, 540, 0, 'ianuarie', 2015, 20, 0, 'restanta_mandat', 'mandat neachitat nam', '', 'ajutor refugiati', 'inclus_in_plata', ''], [8560915350016, 'horo', 'wafa', ' 8560915350016 - horo wafa', 'iunie', 2014, 540, 0, 'ianuarie', 2015, 10, 0, 'restanta_mandat', 'mandat neachitat nam', '', 'ajutor refugiati', 'inclus_in_plata', ''], [7910125350023, 'haj ahmad', 'hussein', ' 7910125350023 - haj ahmad hussein', 'august', 2014, 540, '', '', '', ' ', 0, 'restanta_mandat', 'mandat neachitat nam', '', 'ajutor refugiati', 'in_asteptare', ''], [7910125350023, 'haj ahmad', 'hussein', ' 7910125350023 - haj ahmad hussein', 'septembrie', 2016, 540, '', '', '', ' ', 0, 'restanta_mandat', 'mandat neachitat nam', '', 'ajutor refugiati', 'in_asteptare', ''], [2830203350021, 'braescu', 'anisoara', ' 5051024350070 - braescu abel', 'august', 2014, 42, '', '', '', 42, 0, 'restanta_mandat', 'restit de la banca', '', 'alocatia de stat pentru copii', 'in_asteptare', '']]
and based on first index each list (example:8560915350016) want compare other lists , when found same one: append index 4 , 5 on index 4 position (only when index 10 bigger 0) , sum index 10 value , remain first original entry(no first index duplications), put desired output can understand better, desired output:
[[8560915350016, 'horo', 'wafa', ' 8560915350016 - horo wafa', 'august 2014,iunie 2014' , 540, 0, 'ianuarie', 2015, 30, 0, 'restanta_mandat', 'mandat neachitat nam', '', 'ajutor refugiati', 'inclus_in_plata', ''], [7910125350023, 'haj ahmad', 'hussein', ' 7910125350023 - haj ahmad hussein', 'august 2014', 540, '', '', '', ' ', 0, 'restanta_mandat', 'mandat neachitat nam', '', 'ajutor refugiati', 'in_asteptare', ''], [2830203350021, 'braescu', 'anisoara', ' 5051024350070 - braescu abel', 'august', 2014, 42, '', '', '', 42, 0, 'restanta_mandat', 'restit de la banca', '', 'alocatia de stat pentru copii', 'in_asteptare', '']]
notice how first list example looking right now:
[8560915350016, 'horo', 'wafa', ' 8560915350016 - horo wafa', 'august 2014,iunie 2014' , 540, 0, 'ianuarie', 2015, 30, 0, 'restanta_mandat', 'mandat neachitat nam', '', 'ajutor refugiati', 'inclus_in_plata', '']
what manage far close desired output this:
manipulate=[i in intconvertsafirlistoflists if i[0] not in [intconvertsafirlistoflists[idx][0] idx in range(0,intconvertsafirlistoflists.index(i))]]
intconvertsafirlistoflists beeing list of lists name.
but outputs this:
[[8560915350016, 'horo', 'wafa', ' 8560915350016 - horo wafa', 'august', 2014, 540, 0, 'ianuarie', 2015, 0, 0, 'restanta_mandat', 'mandat neachitat nam', '', 'ajutor refugiati', 'inclus_in_plata', ''], [7910125350023, 'haj ahmad', 'hussein', ' 7910125350023 - haj ahmad hussein', 'august', 2014, 540, '', '', '', ' ', 0, 'restanta_mandat', 'mandat neachitat nam', '', 'ajutor refugiati', 'in_asteptare', ''], [2830203350021, 'braescu', 'anisoara', ' 5051024350070 - braescu abel', 'august', 2014, 42, '', '', '', 42, 0, 'restanta_mandat', 'restit de la banca', '', 'alocatia de stat pentru copii', 'in_asteptare', '']]
it doesn't sum index 10 , doesn't add date index 4 , 5. changes need make in order desired output?
Comments
Post a Comment