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.
#7
Mea culpa. I realise that I misunderstood OP-s problem. I interpreted 'sum of the most present values in the array' as 'most present value in the array i.e. last item present in list'. My bad. Counting part is still relevant but not finding the maximum count value.

Iterating jefsummers code: we can apply key to max function as well, so one can write:

>>> max_count = max(counts.items(), key = lambda kv:kv[1])[1]   # from key, value pair we take only value by using index [1]
>>> max_count
4   
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
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