Stuck on part of function for school which requires me to add all identical integers in a list and return the total. For example given the list [2,3,3] I want 6 to be returned or given a list like [5,6,5], I would like 10 to be returned. Sine I am going to be using this as part of an if-statement, what's the shortest way to do this?
I've tried using indexing but I can't figure out how to get the if-statement to realize which combination of elements are the same so they can be added together and returned.
NOTE: The length of the list will never be more than 3 and I already have the case covered in which all 3 elements are the same. It's just with the combination of two elements which I'm having trouble with.
Aucun commentaire:
Enregistrer un commentaire