New course! Every coder should learn Generative AI!
Try a free lesson+ 1
how to optimize python code?
I have a list of lists Like: l = [ ["Mike", 25, 1500], ["Jane", 23, 2000], ["Mike", 25, 750], ] and if first two elements of inner lists are same I want to merge them and sum the third element of them. Like: res = [ ["Mike", 25, 2250], ["Jane", 23, 2000], ] This is my code: https://code.sololearn.com/c7AQiANvinWd/?ref=app
2 Answers
+ 1
Hisham YUM 🇲🇦 set is useful to remove duplicate, however in this case it is not useful.
Shadoff why are you using a list for this kind of data ? a dictionary will make the parsing easier. you can then create a key for the name and do comparaison
0
Try using Sets instead! Think about it 😉