Python Forum
Quick Lists Question (Count Occurences)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Quick Lists Question (Count Occurences)
#11
If you can not use collections, write your own Counter:

def MyCounter(lst):
    dic = {}
    for e in lst:
        if e in dic:
            dic[e] += 1
        else:
            dic[e] = 1
    return dic

lst = []
print("Enter 9 numbers: ")
for i in range(9):
    lst.append(int(input()))

print(MyCounter(lst))
Reply
#12
(Nov-16-2016, 05:10 PM)nilamo Wrote:
(Nov-16-2016, 05:04 PM)metulburr Wrote: I thought you couldnt use collections?
That's not OP.

whoops lol 
LOL
Recommended Tutorials:
Reply
#13
Thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Count occurences in a string and add to a list using loops Leyo 4 1,637 Mar-11-2022, 03:52 PM
Last Post: Leyo
  Calculator I need quick help Malin3k 3 2,028 Feb-13-2021, 02:10 AM
Last Post: BashBedlam
  Count Letters in a Sentence (without using the Count Function) bhill 3 5,063 Jun-19-2018, 02:52 AM
Last Post: bhill
  regex, counting occurences yanhto 4 3,311 May-06-2018, 10:20 PM
Last Post: killerrex

Forum Jump:

User Panel Messages

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