Python Forum
help with adding duplicates elements together in a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with adding duplicates elements together in a list
#1
given a list(just an example list, the actual test list is much MUCH longer)

d = [6610013121,4,6610021021,5, 6610021021,5,6610061121,5, 6610061121,5, 6610061121,1,6610000121,3, 6610000121,2, 6610000121,2, 6610000121,3]

where the long number is the student id number and the following number is the score(can be any positive or negative number) they receive.

The exercise is to add together the scores of each student and print them out as: list = [6610013121,4, 6610021021,10, 6610061121,11, 6610000121,8]
This requires me to find the duplicate id, add their respective points, and append that to a new list.
My problem is I can't figure out how to find duplicates id and add their scores together with these restrictions:
1. no dict() and set() allowed
2. no importing of library
3. if there are more than 4 scores remove the lowest one from the summation of that student. ex: [6610000121,3, 6610000121,2, 6610000121,2, 6610000121,3] is equal to [6610000121,8] since one of the "2" are considered lowest and removed
Reply


Messages In This Thread
help with adding duplicates elements together in a list - by 2ECC3O - Sep-09-2022, 05:10 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to sort a list with duplicates and return their unique indices. Echoroom 3 3,510 Sep-23-2022, 07:53 AM
Last Post: deanhystad
  Unexpected behavior accessing list elements. tonyflute 2 2,270 Apr-09-2021, 02:36 PM
Last Post: tonyflute
  How to find difference between elements in a list? Using beginner Basics only. Anklebiter 8 4,363 Nov-19-2020, 07:43 PM
Last Post: Anklebiter
  Dealing with duplicates to an Excel sheet DistraughtMuffin 6 3,279 Oct-28-2020, 05:16 PM
Last Post: Askic
  Get 5 most unique combinations of elements in a 2D list wanttolearn 1 2,316 Sep-24-2020, 02:26 PM
Last Post: buran
  Loop through elements of list and include as value in the dictionary Rupini 3 2,657 Jun-13-2020, 05:43 AM
Last Post: buran
  Python Adding +1 to a list item cointained in a dict ElReyZero 1 2,081 Apr-30-2020, 05:12 AM
Last Post: deanhystad
  How can I print the number of unique elements in a list? AnOddGirl 5 3,298 Mar-24-2020, 05:47 AM
Last Post: AnOddGirl
  adding parts of a list Eric7Giants 4 2,758 Nov-17-2019, 05:53 PM
Last Post: buran
  duplicates nsx200 3 2,442 Nov-12-2019, 08:55 AM
Last Post: nsx200

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020