Python Forum
Need to speed up my code.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need to speed up my code.
#1
I have to return a simple sum of the most present values in the array, ie [3,5,2,1,2,3,2,2] - > should return 4, because (2,2,2,2).
The array sometimes is crazy focking big, and I cannot pass the execution time limit on the website that im practicing.

My code now is like that:

def birthdayCakeCandles(ar):
    def count_em(x):
        fin = ar.count(x)
        ar.remove(x)
        return fin

    return max(map(count_em,ar))
ar.remove is to not repeat the iteration for every occurrence of a same value, but it doesnt even feel like a speed up, is it even cached in cpu this way?
Reply


Messages In This Thread
Need to speed up my code. - by blackknite - Jan-14-2020, 05:04 PM
RE: Need to speed up my code. - by Gribouillis - Jan-14-2020, 06:49 PM
RE: Need to speed up my code. - by ndc85430 - Jan-15-2020, 08:36 AM
RE: Need to speed up my code. - by blackknite - Jan-19-2020, 01:24 AM
RE: Need to speed up my code. - by perfringo - Jan-19-2020, 07:57 AM
RE: Need to speed up my code. - by jefsummers - Jan-19-2020, 02:02 PM
RE: Need to speed up my code. - by perfringo - Jan-20-2020, 08:24 AM

Forum Jump:

User Panel Messages

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